简体   繁体   中英

Why can't I see my taken pictures in gallery?

I am experimenting with the Camera on my non-rooted 4.0.4 Android device having no sd-card. I am doing some burst-shots and saving them on the internal memory.

My problem is that my photos get stored in /data/data/my.package.name/files which I cannot access without root-permission. I can see the files, but they have no read-permission.

I found some broadcast-Intent that should make them visible in the standard-gallery, but that doesn't seem to work neither.

Does anyone have another idea of how I can access my photos? Or tweak the stuff I tried so far?

how I save the photos:

public void onPictureTaken(byte[] data, Camera camera) {
        FileOutputStream outStream = null;
        try {           
            Log.i(TAG, ""+Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES));           
            Log.i(TAG,"fotofolder is "+getFilesDir());

            // write to local sandbox file system
             outStream = CameraDemo.this.openFileOutput(String.format("%d.jpg",
             System.currentTimeMillis()), 0);

            outStream.write(data);
            outStream.close();

       //this intent should make fotos visible in the gallery
            sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,                           
                     Uri.fromFile(Environment.getExternalStorageDirectory())));
                    // Uri.parse("file://" + Environment.getExternalStorageDirectory())));

            Log.i(TAG, "onPictureTaken - wrote bytes: " + data.length);
     ...
}

the log:

08-23 12:42:49.324: I/FrontCamera(15832): /mnt/sdcard/Pictures
08-23 12:42:49.327: I/FrontCamera(15832): fotofolder is /data/data/com.example.camera/files
08-23 12:42:49.370: I/FrontCamera(15832): onPictureTaken - wrote bytes: 430493

<--- it puts the photos to the data/data... folder, instead of the useful mnt/sdcard/Pictures

Use MediaStore.Images.Media

MediaStore.Images.Media.insertImage(getContentResolver(), imageBitmap, imageTitle, imageDescription);

you can use the internal storage for saving.

To reflect image in gallery try this:

MediaScannerConnection.scanFile(DetailsActivity.this, new String[] {filepath }, null, new OnScanCompletedListener() {

                                                @Override
                                                public void onScanCompleted(String path, Uri uri) {

                                                }
                                            });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM