Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android-将图片添加到gallery应用程序_Android_Image Gallery - Fatal编程技术网

android-将图片添加到gallery应用程序

android-将图片添加到gallery应用程序,android,image-gallery,Android,Image Gallery,我有一个可以拍照的应用程序,它们都是全尺寸上传的。我希望它们显示在gallery应用程序中。我正在使用: private void galleryAddPic() { Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); File f = new File(imagepath); Uri contentUri = Uri.fromFile(f); mediaScanI

我有一个可以拍照的应用程序,它们都是全尺寸上传的。我希望它们显示在gallery应用程序中。我正在使用:

private void galleryAddPic() {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    File f = new File(imagepath);
    Uri contentUri = Uri.fromFile(f);
    mediaScanIntent.setData(contentUri);
    this.sendBroadcast(mediaScanIntent);
}

它在5.0中有效,但在4.3中无效。
imagepath
是一个绝对路径

试试这样的方法

private void galleryAddPhoto() {
    sendBroadcast(
            new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
                    Uri.parse("file://" + mCurrentFilteredPhotoPath))
    );
}
此方法将使用文件的位置将文件添加到库中,其中mCurrentFilteredPhotoPath是一个字符串对象