Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Intent selectionintent = new Intent(Intent.ACTION_GET_CONTENT);
- selectionintent.setType("application/pdf");
- selectionintent.addCategory(Intent.CATEGORY_OPENABLE);
- PackageManager packageManager = getPackageManager();
- List activitiesPDF = packageManager.queryIntentActivities(selectionintent,
- PackageManager.MATCH_DEFAULT_ONLY);
- boolean isIntentSafePDF = activitiesPDF.size() > 0;
- if (isIntentSafePDF)
- startActivityForResult(selectionintent, CODE_RESULT);
- else
- Toast.makeText(UpdateFileActivity.this, "Only select pdf files", Toast.LENGTH_SHORT).show();
- if (requestCode == CODE_RESULT && resultCode == RESULT_OK) {
- Uri uri = data.getData();
- String file = uri.toString();
- File f = new File(file);
- if (file.startsWith("content://")) {
- Cursor cursor = null;
- try {
- cursor = getContentResolver().query(uri, null, null, null, null);
- if (cursor != null && cursor.moveToFirst()) {
- displayName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
- }
- } finally {
- cursor.close();
- }
- } else if (file.startsWith("file://")) {
- displayName = f.getName();
- }
- filetext.setText(displayName);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement