简体   繁体   English

为什么在图库中看不到我拍摄的照片?

[英]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. 我正在无根4.0.4 Android设备(没有SD卡)上使用Camera进行实验。 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. 我的问题是我的照片存储在/data/data/my.package.name/files ,如果没有root权限,我将无法访问它们。 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 <---将照片放入data/data...文件夹,而不是有用的mnt/sdcard/Pictures

Use MediaStore.Images.Media 使用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) {

                                                }
                                            });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我在画廊中看不到我的一些照片? - Why can't I see some of my pictures in the gallery? 从我的应用程序拍摄的照片,保存在正确的文件夹中,但在图库中看不到 - Photo taken from my app, saved in the right folder but can't see in the gallery 我看不到“画廊”小部件,未显示图片 - I cannot see my Gallery widget, no pictures are shown 如果图片是使用 android 的相机应用程序拍摄的,为什么我无法在我的 android 应用程序中上传图片库中的图片? - Why can't I upload a picture from gallery in my android app, if the picture was taken with the camera app from android? 我看不到我的LinearLayout,为什么? - I can't see my LinearLayout, why? 为什么我的应用拍摄的照片在Android中为0尺寸? - Why pictures taken by my app are 0 size in Android? 我可以通过我的应用程序监视Android原生相机应用程序拍摄的照片吗? - Can I monitor pictures taken by Android native camera app via my app? 为什么我在设备上看不到ImageView? - Why i can't see ImageView on my device? 为什么我在avd应用程序菜单中看不到我的应用程序? - Why can't I see my app in the avd app menu? 为什么在XML Android Studio中看不到我的设计? - Why can't I see my design in XML Android Studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM