문제

I'm using MediaStore.ACTION_IMAGE_CAPTURE to take a picture with MediaStore.EXTRA_OUTPUT to point to the Uri for the DCIM/Camera directory where all the other photo/video files are stored.

The photo file is successfully taken and I can see it using ES File Explorer and can view it inside my app. However it is not shown in the gallery when I use Intent.ACTION_PICK

Intent selectPictureIntent = new Intent(Intent.ACTION_PICK);
        selectPictureIntent.setType("image/*");

I've read the other topics on updating the Gallery after the picture comes back using

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, 
                 Uri.parse("file://"+ Environment.getExternalStorageDirectory())));

and also

Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, _outputMediaUri);     
        LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(intent);

What's going on here :(

도움이 되었습니까?

해결책

why did you use LocalBroadcastManager? LocalBroadcastManager can only send broadcast data inside of your app. Try to use

Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, _outputMediaUri);     
sendBroadcast(intent);

Gallery always listens to URI change. After file event broadcast to Gallery, the data stored in Gallery will be updated.

다른 팁

it also can problem with KITKAT build version.. for sure you can use this code:

   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                    Intent mediaScanIntent = new Intent(
                            Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                    Uri contentUri = Uri.fromFile(out); \\out is your output file
                    mediaScanIntent.setData(contentUri);
                    this.sendBroadcast(mediaScanIntent);
                } else {
                    sendBroadcast(new Intent(
                            Intent.ACTION_MEDIA_MOUNTED,
                            Uri.parse("file://"
                                    + Environment.getExternalStorageDirectory())));
                }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top