0
我是新的android开发。我试图创建一个PDF文件使用Android应用程序和通过应用程序查看。当我创建PDF文件没有错误,但它会引发和异常,当我尝试打开PDF文件。我还在清单文件中设置了读写权限。 这里是我的方法来打开PDF文件ActivityNotFoundException当尝试在Android应用程序中打开PDF文件
void openPdf()
{
Intent intent = new Intent(Intent.ACTION_VIEW);
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/PDF";
File file = new File(path, "demo.pdf");
intent.setDataAndType(Uri.fromFile(file), "application/pdf");
startActivity(intent.setDataAndType(Uri.fromFile(file), "application/pdf"));
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
Intent target = Intent.createChooser(intent, "Open File");
try {
startActivity(target);
} catch (ActivityNotFoundException e) {
Log.e("PDFCreator", "ActivityNotFoundException:" + e);
}
}
这是我得到的错误
03-28 05:47:59.760: E/AndroidRuntime(5844): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///storage/sdcard/PDF/demo.pdf typ=application/pdf }
这里是我的清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.isuru.mypdf"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.isuru.mypdf.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
为什么这个错误出现,请帮我解决问题。天气我不得不改变核心或添加一些cording。非常感谢你
你的意思是我必须为我的模拟器安装pdf开放应用程序,如何做到这一点? – ISURU
您必须安装,以便您的应用程序可以使用此安装的应用程序打开你PDF –
从http://www.kingsoftstore.com/download-office/android-office-apps.html下载金山办公室,并安装该apk到你的模拟器进行测试..要安装APK模拟器“adb install kingsoftapp.apk” –