Question

I'm new to android development. I'm trying to create a PDF file using android application and view through the application.there is no error when i creating the pdf file, but it throws and exception when i try to open the pdf file. I also set the read and write permission in the manifest file. here is my method to open the pdf file

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

this the error that i get

 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 }

here is my manifest file

   <?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>

why this error comes,please help me to solve the problem. weather i have to change the cored or add some cording. thank you very much

Was it helpful?

Solution

Please check on your phone/Emulator that PDF opening application (Any app having Mapped action with "android.intent.action.VIEW") is installed or not. If not please install adobe reader or any pdf opening app and try again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top