PDF файл не открывается на андроид - PullRequest
0 голосов
/ 08 ноября 2019

Я использую этот код для открытия файла PDF в папке загрузок

public void open_pdf(View view) {
    String fileName ="2019_10_22_03_37_25_pm5906.pdf";

    File pdfFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath()
            + File.separator + fileName);
    Uri path = Uri.fromFile(pdfFile);
    Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
    pdfIntent.setDataAndType(path, "application/pdf");
    pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    Toast.makeText(this, "hello: "+pdfFile, Toast.LENGTH_SHORT).show();

    t1 =  findViewById(R.id.textView);
    t1.setText(path.toString() + "####"+pdfFile.getPath());
    try{
        startActivity(pdfIntent);

    }catch(ActivityNotFoundException e){
        Toast.makeText(this, "No Application available to view PDF", Toast.LENGTH_SHORT).show();
        t1.setText("No applicatoin available");
    } catch ( Exception e){
        Toast.makeText(this, "No App found, sorry", Toast.LENGTH_SHORT).show();
    } finally {
        Toast.makeText(this, "This is finally block", Toast.LENGTH_SHORT).show();
    }
}

Есть несколько проблем

  1. Файл PDF не открывается, URI= file: ///storage/emulated/0/Download/2019_10_pm.pdf мне кажется правильным

  2. Не вызывается исключение и нет ошибки.

В чем может быть проблема? Я новичок в программировании Android

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...