Limitations on opening pdf file in Android

前端 未结 6 1495
暗喜
暗喜 2021-02-11 15:04

I am trying to opening some pdf from my Android application. I am using an Intent for doing that:

Intent intent = new Intent();
intent.setDataAndType(Uri.parse(u         


        
6条回答
  •  长发绾君心
    2021-02-11 16:04

    Using an intent to open a pdf file with https:// protocol, definitelly https:// isn´t the problem.

    I see that you are trying this method defining the data type:

    Intent intent = new Intent();
    intent.setDataAndType(Uri.parse(url), "application/pdf");
    startActivity(intent);
    

    but it will cause:

    ActivityNotFoundException: No Activity found to handle Intent

    if you use this other method probably you can´t see PDF readers in the options to open this kind of files:

      Intent intent = new Intent();
      intent.setDataAndType(Uri.parse(url), "application/pdf");
      Intent chooserIntent = Intent.createChooser(intent, "Open Report");
      startActivity(chooserIntent);
    

    You must try this method without the type definition and it will work perfectly:

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(url));
    startActivity(intent);
    

    Other cause of this problem opening the pdf file via intent would be the default application to open this kind of files, so probably you will have a corrupt or invalid application configured, so reset the defaults:

    Go to Settings. Tap Applications. Tap Default Applications.

    Select the app and Clear defaults

提交回复
热议问题