Я работаю над приложением, где нужно открыть файл pdf на устройстве,
Я действительно получил код в Интернете, который похож на большинство примеров. Но дело в том, что я не могу открыть файл, и элемент управления напрямую переходит к части "Исключение".
Вот код ниже:
public class MyPDFDemo extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button OpenPDF = (Button) findViewById(R.id.button);
OpenPDF.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
File pdfFile = new File("/sdcard/Determine_RGB_Codes_With_Powerpoint [PDF Library].pdf");
if(pdfFile.exists())
{
Uri path = Uri.fromFile(pdfFile);
Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
pdfIntent.setDataAndType(path, "application/pdf");
pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try
{
startActivity(pdfIntent);
}
catch(ActivityNotFoundException e)
{
Toast.makeText(MyPDFDemo.this, "No Application available to view pdf", Toast.LENGTH_LONG).show();
}
}
}
});
}
Когда я запускаю этот код: я использовал для просмотра "Нет приложения для просмотра pdf". Могу ли я кому-нибудь просмотреть файл в формате pdf.