0

I'm trying to create a pdf opener on my android emulator (2.3.3), however it is returning an Activitynotfound exception every time i run it. I've checked the package name and the class name and it is correct. I am also quite new in Android development. Here are the codes!

public class PdfViewerActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    TextView tv = new TextView(this);


    File file = new File("mnt/sdcard/proposal.pdf");
    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri path2 = Uri.fromFile(file);
    intent.setDataAndType(path2, "application/pdf");    

    try 
    { 
         startActivity(intent);
    } 
    catch(ActivityNotFoundException e ) 
    { 
        tv.setText("What the hell is going on O_O" + "\n" + e);
        setContentView(tv);  
    } 


}

}

==========

Manifest

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".PdfViewerActivity"
              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>

skaffman
  • 398,947
  • 96
  • 818
  • 769

3 Answers3

1

Thereis no PDF viewer application installed on your phone. That's why the start activity code here is failing. What exactly do you mean by a PDF opener?

Kumar Bibek
  • 9,016
  • 2
  • 39
  • 68
0

When you launch the intent for ACTION_VIEW, do you have an activity that "catches" it?

JM Macariola
  • 103
  • 1
  • 4
  • i'm sorry im new at all of this. What do you mean by "Catches it"? all the code i have is up there on qn so if it's not there i probably don;t have it – Azliaris Jul 13 '11 at 03:28
  • 1
    apolgies, I might not have worded it correctly. When you do a **startActivity(intent)** call, you'd be starting a new activity based on whatever request is in your intent. What activity are you hoping to start with your call? Do you already have an app in your phone/emulator that would cater to viewing a PDF? – JM Macariola Jul 13 '11 at 04:16
  • nope, i'm required to open a pdf file stored in the sdcard. Isn't this the way to open it? I know android cannot open .pdf files natively – Azliaris Jul 13 '11 at 04:26
  • 1
    Exactly. you have the PDF file in your sdcard, but you don't have an app in your OS that opens PDF files. It's like you have a PC with no Adobe Reader or whatever PDF viewer (including browsers), and then you try to open a file. It gives you a pop-up saying it doesn't know what program to use right? In your app, you get an activity not found exception because there is currently no app in your phone that can open PDF files. Hope this explains it and good luck! – JM Macariola Jul 13 '11 at 04:34
0

You are using emulator for read PDf and the way you are reading PDF is Intent.ACTION_VIEW for that you need one Pdf reading application install in your emulator.

If you want to read Pdf there is some other way you can read

Android - Load PDF / PDF Viewer

Also you can make your own PDF Viewer

Community
  • 1
  • 1
Dharmendra
  • 33,296
  • 22
  • 86
  • 129