我有一個打開pdf文件的應用程序,我們點擊按鈕。這是functionnal Android上的所有版本,但它墜毀在Android 7.1.1,我不知道爲什麼:/Android 7.1.1上的ActivityNotFoundException
這是我看過
ActivityNotFoundException when starting
No Activity found to handle Intent splash screen
的相關問題我的功能,在MainActivity打開文件:
private void readPDF({
File f = new File(getFilesDir(), "toto.pdf");
if (!f.exists()) {
AssetManager assets=getResources().getAssets();
try {
copy(assets.open("toto.pdf"), f);
}
catch (IOException e) {
Log.e("FileProvider", "Exception copying from assets", e);
}
}
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = getUriForFile(this, getApplicationContext().getPackageName() + ".fileprovider", f);
intent.setDataAndType(uri, "application/pdf");
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
revokeUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
}
private void copy(InputStream in, File dst) throws IOException {
FileOutputStream out=new FileOutputStream(dst);
byte[] buf=new byte[1024];
int len;
while ((len=in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
我的清單:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.fr">
<application
android:allowBackup="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.fr.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
<activity
android:name="com.example.fr.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
最後錯誤代碼:
八月4日至26日:15:16.991 21748-21748/com.example.fr E/AndroidRuntime:致命異常:主 過程: com.example.fr,PID:21748 android.content.ActivityNotFoundException:找不到處理Intent的活動{act = android.intent.action.VIEW dat = content://com.example.fr.fileprovider/assets/toto。 pdf typ = application/pdf flg = 0x1} at android.app .Instrumentation.checkStartActivityResult(Instrumentation.java:1809) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1523) at android.app.Activity.startActivityForResult(Activity.java:4225) at android.support.v4在android.app.Activity.startActivityForResult(Activity.java:4183) at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:871) at android.app.Activity.startActivity(Activity.java:4522)012 (MainActivity.java:58) at com.example.fr.MainActivity.access $ 000(MainActivity.java) :21) at com.example.fr.MainActivity $ 1.onClick(MainActivity.java:34) at android.view.View.performClick(View.java:5637) at android.view.View $ PerformClick.run( Android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper。 java:154)(Native Method) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java()方法) :886) at com.android.internal.os.ZygoteInit.main(ZygoteInit。Java的:776)
感謝的對你有所幫助
您希望處理PDF文件的用途是什麼?可能沒有安裝這樣的應用程序 –