yuyue-ren / apdfviewer

Automatically exported from code.google.com/p/apdfviewer
0 stars 0 forks source link

Any sample code for viewing a pdf file? #24

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Is there any sample code to view a pdf file? I got an empty screen when I 
compile the latest source code. So I add a new main activity. And add the 
following code when I click a button to open a pdf in my sdcard:

                // open pdfviewactivity
                File dir = Environment.getExternalStorageDirectory();
                File yourFile = new File(dir, "book.pdf");

                Intent intent =  new Intent(Intent.ACTION_VIEW, Uri.fromFile(yourFile));
                startActivity(intent);              

Unfortunately it crashes. The error message is:

05-16 13:13:36.652: E/AndroidRuntime(12364): FATAL EXCEPTION: main
05-16 13:13:36.652: E/AndroidRuntime(12364): 
android.content.ActivityNotFoundException: No Activity found to handle Intent { 
act=android.intent.action.VIEW dat=file:///mnt/sdcard/book.pdf }

My androidmanifest.xml is:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.googlecode.apdfviewer" >

    <application android:label="@string/app_name" >
        <activity
            android:name="com.googlecode.apdfviewer.PDFViewerActivity"
            android:label="PDFViewer"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="file" />
                <data android:scheme="content" />
                <data android:mimeType="application/pdf" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.googlecode.apdfviewer.MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Any clue? Thanks.

Original issue reported on code.google.com by bagusfl...@gmail.com on 16 May 2013 at 1:22