[英]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.