Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android隐式意图不';有些设备不能工作_Android_Exception_Android Intent_Android Activity_Android Api Levels - Fatal编程技术网

Android隐式意图不';有些设备不能工作

Android隐式意图不';有些设备不能工作,android,exception,android-intent,android-activity,android-api-levels,Android,Exception,Android Intent,Android Activity,Android Api Levels,我正试图通过使用如下隐式意图从uri打开pdf文件: try{ Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(pdfUri, "application/pdf"); startActivity(in

我正试图通过使用如下隐式意图从uri打开pdf文件:

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());
}

这在我的OnePlus X(API级别23)上运行得非常好,但是我在三星GT S7582(API级别17)上尝试了它,由于某种原因它不起作用

然后我尝试使用IntentChooser,但这也不起作用:

Intent chooser = Intent.createChooser(intent, "Open with");
startActivity(chooser)
之后,我尝试共享一个字符串,这在两台设备上都非常有效:

 Intent intent = new Intent();
 intent.setAction(Intent.ACTION_SEND);
 intent.putExtra(Intent.EXTRA_TEXT, "Test 123 abc");
 intent.setType("text/plain");
 startActivity(intent);
两台设备上都明确安装了能够打开PDF文件的应用程序,并且不会引发ActivityNotFoundException


有人知道为什么intent在某些设备上不起作用吗?

“出于某种原因它不起作用”——请详细解释您的意思。您指示未抛出
ActivityNotFoundException
。那么,抛出的是什么?或者,“不工作”是什么意思?另外,
pdfUri
的价值是什么?@commonware事实证明是
pdfUri
导致了这个问题,因为我在打开pdf文件之前不久编写了它,而这个编写过程在较低api级别的设备上失败了,因为我没有在清单中声明
android.permission.WRITE_EXTERNAL_STORAGE
。谢谢你指点我,给我带来不便,非常抱歉。