Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. Intent selectionintent = new Intent(Intent.ACTION_GET_CONTENT);
  2. selectionintent.setType("application/pdf");
  3. selectionintent.addCategory(Intent.CATEGORY_OPENABLE);
  4. PackageManager packageManager = getPackageManager();
  5.  
  6. List activitiesPDF = packageManager.queryIntentActivities(selectionintent,
  7. PackageManager.MATCH_DEFAULT_ONLY);
  8. boolean isIntentSafePDF = activitiesPDF.size() > 0;
  9. if (isIntentSafePDF)
  10. startActivityForResult(selectionintent, CODE_RESULT);
  11. else
  12. Toast.makeText(UpdateFileActivity.this, "Only select pdf files", Toast.LENGTH_SHORT).show();
  13.  
  14. if (requestCode == CODE_RESULT && resultCode == RESULT_OK) {
  15. Uri uri = data.getData();
  16. String file = uri.toString();
  17. File f = new File(file);
  18. if (file.startsWith("content://")) {
  19. Cursor cursor = null;
  20. try {
  21. cursor = getContentResolver().query(uri, null, null, null, null);
  22. if (cursor != null && cursor.moveToFirst()) {
  23. displayName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
  24. }
  25. } finally {
  26. cursor.close();
  27. }
  28. } else if (file.startsWith("file://")) {
  29. displayName = f.getName();
  30. }
  31. filetext.setText(displayName);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement