0

good morning i used a code to open pdf file that exist in asset folder but the app crash every time with this message unable to start activity Pdfreader ActivityNoFoundExeption NoActivity found to handle intent this the code

package com.example.albir;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

public class Pdfreader extends Activity {
     @Override
     protected void onCreate(Bundle savedInstanceState)
     {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.pdf);
         CopyReadAssets();

     }

     @SuppressLint("WorldReadableFiles")
    @SuppressWarnings("deprecation")
    private void CopyReadAssets()
     {
         AssetManager assetManager = getAssets();

         InputStream in = null;
         OutputStream out = null;
         File file = new File(getFilesDir(), "beralahsa001.pdf");
         try
         {
             in = assetManager.open("beralahsa001.pdf");
             out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE);

             copyFile(in, out);
             in.close();
             in = null;
             out.flush();
             out.close();
             out = null;
         } catch (Exception e)
         {
             Log.e("tag", e.getMessage());
         }

         Intent intent = new Intent(Intent.ACTION_VIEW);
         intent.setDataAndType(
                 Uri.parse("file://" + getFilesDir() + "/beralahsa001.pdf"),
                 "application/pdf");

         startActivity(intent);
     }

     private void copyFile(InputStream in, OutputStream out) throws IOException
     {
         byte[] buffer = new byte[1024];
         int read;
         while ((read = in.read(buffer)) != -1)
         {
             out.write(buffer, 0, read);
         }
     }

}

this is the manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.albir"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />
     <uses-permission android:name="android.permission.INTERNET"/>  
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.albir.Menu"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".ShowDetails"></activity>
        <activity android:name=".MainActivity"></activity>
        <activity android:name=".Pdfreader"></activity>

    </application>

</manifest>

can you please help me

Walid Sassi
  • 75
  • 1
  • 2
  • 11

2 Answers2

1

It seems as the intent resolver can't find anything that can handle PDFs. Try installing a PDF viewer on your device.

OrhanC1
  • 1,415
  • 2
  • 14
  • 28
  • can you help please i had an other pb but none respond me if you have any idea how scrooling a image http://stackoverflow.com/questions/25491060/error-inflating-imageview-in-scrollview-android – Walid Sassi Aug 26 '14 at 11:01
1

Try it..

AssetManager assetManager = getAssets();


InputStream in = null;
OutputStream out = null;
File file = new File(getFilesDir(), "pdfname.pdf");
try
{
in = assetManager.open("pdfname.pdf");
out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE);


copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch (Exception e)
{
Toast.makeText(getApplicationContext(), "no pdf viewer", 2000).show();
finish();
}
try{
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(
Uri.parse("file://" + getFilesDir() + "/pdfname.pdf"),
"application/pdf");


startActivity(intent);
finish();
}
catch (Exception e)
{
Toast.makeText(getApplicationContext(), "no pdf viewer", 2000).show();
finish();
}
}


private void copyFile(InputStream in, OutputStream out) throws IOException
{
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1)
{
out.write(buffer, 0, read);
}
}
bagher
  • 7
  • 2