zach14c

android.intent.action.GET_CONTENT

Nov 27th, 2018
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. if (ContextCompat.checkSelfPermission(MainActivity.this,
  2. Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager. PERMISSION_GRANTED) {
  3. ActivityCompat.requestPermissions(MainActivity.this, new String[]{ Manifest.permission. WRITE_EXTERNAL_STORAGE }, 1);
  4. } else { openAlbum();
  5. } }
  6. }); }
  7. private void openAlbum() {
  8. Intent intent = new Intent("android.intent.action.GET_CONTENT"); intent.setType("image/*");
  9. startActivityForResult(intent, CHOOSE_PHOTO); // 打开相册 }
  10. @Override
  11. public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
  12. switch (requestCode) { case 1:
  13. if (grantResults.length > 0 && grantResults[0] == PackageManager. PERMISSION_GRANTED) {
  14. openAlbum(); } else {
  15. Toast.makeText(this, "You denied the permission", Toast.LENGTH_SHORT).show();
  16. } break;
  17. default: }
  18. }
Add Comment
Please, Sign In to add comment