开发者

Android - action pick cancel button

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜