Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 422576c

Browse files
committed
Resolving issue 104: Fatal exception in sample if try to pick file without file manager. By many users won't have a file manager installed by default. Resolved issue by catching exception and displaying Toast.
1 parent 187fbf5 commit 422576c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

sample/src/main/java/com/github/barteksc/sample/PDFViewActivity.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
*/
1616
package com.github.barteksc.sample;
1717

18+
import android.content.ActivityNotFoundException;
1819
import android.content.Intent;
1920
import android.database.Cursor;
2021
import android.net.Uri;
2122
import android.provider.OpenableColumns;
2223
import android.support.v7.app.AppCompatActivity;
2324
import android.util.Log;
25+
import android.widget.Toast;
2426

2527
import com.github.barteksc.pdfviewer.PDFView;
2628
import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener;
@@ -63,7 +65,13 @@ public class PDFViewActivity extends AppCompatActivity implements OnPageChangeLi
6365
void pickFile() {
6466
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
6567
intent.setType("application/pdf");
66-
startActivityForResult(intent, REQUEST_CODE);
68+
try {
69+
startActivityForResult(intent, REQUEST_CODE);
70+
}
71+
catch (ActivityNotFoundException e) {
72+
//alert user that file manager not working
73+
Toast.makeText(this, R.string.toast_pick_file_error, Toast.LENGTH_SHORT).show();
74+
}
6775
}
6876

6977
@AfterViews
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<resources>
22
<string name="app_name">AndroidPdfViewer demo</string>
33
<string name="pick_file">Pick file</string>
4+
<string name="toast_pick_file_error">Unable to pick file. Check status of file manager.</string>
45
</resources>

0 commit comments

Comments
 (0)