开发者

Android - action pick cancel button

开发者 https://www.devze.com 2023-04-12 02:59 出处:网络
I am using the follow bit of code found in an开发者_如何学Cother question here to open a gallery of images from which the user can select an image to load into my app.

I am using the follow bit of code found in an开发者_如何学Cother question here to open a gallery of images from which the user can select an image to load into my app.

startActivityForResult(new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), SELECT_IMAGE);

However, when there are no images found in the memory, an empty gallery is shown, with no cancel button. Is there any way to have a cancel or back button in the view?


We can not add back or cancel button instead what you can do is the following.

  1. Query MediaStore for Images internal as well as External.
  2. If Returned Cursor getCount() have number of records more than Zero then only start gallery activity otherwise show toast message to user that no images found in your phone.

You can use following coding snippet.

ContentResolver cr = getContentResolver();
    Uri uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
    Cursor csr = managedQuery(uri, null, null, null, null);
    System.out.println("Number of images on sdcard "+csr.getCount());
    csr = managedQuery(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, null, null, null, null);
    System.out.println("number of images on internal storage "+csr.getCount());

Cheers...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号