0

I'm trying to open a pdf file from a uri by using an implicit intent like so:

try{
    Intent intent = new Intent();                                   
    intent.setAction(Intent.ACTION_VIEW);                                 
    intent.setDataAndType(pdfUri, "application/pdf");
    startActivity(intent);
}catch(ActivityNotFoundException e){
    e.printStackTrace();
    Log.e(LOG_TAG,e.getMessage());
}

And this works perfectly fine on my OnePlus X(API-Level 23), but the I tried it on a Samsung GT S7582 (API-Level 17), where it's not working for some reason.

I then tried to use an IntentChooser, but this also did not worked:

Intent chooser = Intent.createChooser(intent, "Open with");
startActivity(chooser)

After that I tried to share a string and that worked perfectly fine on both devices:

 Intent intent = new Intent();
 intent.setAction(Intent.ACTION_SEND);
 intent.putExtra(Intent.EXTRA_TEXT, "Test 123 abc");
 intent.setType("text/plain");
 startActivity(intent);

An app which is capable of opening PDF files is definitly installed on both devices and the ActivityNotFoundException is not thrown.

Has anyone any idea why the intent isn't working on some devices?

Steve2955
  • 639
  • 1
  • 5
  • 17
  • "it's not working for some reason" -- please explain, in detail, what you mean by this. You indicate that `ActivityNotFoundException` is not being thrown. So, what *is* being thrown? Or, what does "not working" mean? Also, what is the value of `pdfUri`? – CommonsWare Jan 07 '17 at 20:49
  • @CommonsWare As it turns out `pdfUri` was actually causing the issue, because I'm writing the pdf file shortly before opening it and this writing process failed on the lower api level devices because i didn't declared `android.permission.WRITE_EXTERNAL_STORAGE` in the manifest. Thank you for pointing me towards this and sorry for the inconvenience. – Steve2955 Jan 07 '17 at 21:04

0 Answers0