Android画廊没有更新照片& ACTION_GET_CONTENT问题

时间:2014-03-04 05:24:26

标签: android filter gallery photo

我目前正在使用我通过GridLayout构建的照片库,但在处理大量位图时,这似乎使用了大量内存(OOME即将出现)。因此,我正在尝试使用Intent.ACTION_GET_CONTENT在设备上打开照片并通过那里选择照片。 相机功能在拍摄照片时正常工作,返回onActivityResult功能,并将其更新到我的Gridlayout照片库。

我目前正在使用运行Android 4.4(KitKat)的Nexus 7

[问题]

  • 当我尝试通过Intent.ACTION_GET_CONTENT查看照片时,我刚刚通过该应用程序拍摄的所有新照片都没有。
  • 运行Intent.ACTION_GET_CONTENT来过滤特定目录和文件类型的结果似乎不起作用。

[代码信息]

MainForm 是(类)
photoPath =新文件(目录,photoName)
目录是设置为当前工作目录的(文件)
photoName 是一个(字符串)
CAMERA_CODE 是(int)

[我的代码]

以下是启动相机的代码:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cUri = Uri.fromFile(photoPath);
intent.putExtra(MediaStore.EXTRA_OUTPUT, cUri);
startActivityForResult(intent, CAMERA_CODE); // launch camera

[我尝试了什么+更新照片库的错误]

MediaScannerConnection

我尝试使用它来更新photolist,然后启动intent,但它不起作用(我可能使用的不正确,但在this post中有人建议)

MediaScannerConnection.scanFile(MainForm.this, new String[] { directory.getAbsolutePath() },null, new MediaScannerConnection.OnScanCompletedListener() {
    public void onScanCompleted(String path, Uri uri){
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
        intent.setData(uri);
        intent.setType("image/*");
        startActivityForResult(Intent.createChooser(intent,"Select Picture"), 12345);
    }
});

getContentResolver()

我在this question中读到尝试使用此方法,但它似乎无法正常工作

MainForm.this.getContentResolver().notifyChange(MediaStore.Images.Media.INTERNAL_CONTENT_URI, null);

sendBroadcast

this questionhere中重新索引设备上的照片,建议使用sendBroadcast

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.fromFile(directory)));

但是我遇到了这个错误

  

E / AndroidRuntime(30177):java.lang.SecurityException:Permission Denial:不允许从pid = 30177发送广播android.intent.action.MEDIA_MOUNTED,uid = 10122

这个错误是什么意思?

[我尝试了什么+ ACTION_GET_CONTENT意图的错误]

无论我在intent.setData下放置什么,打开intent似乎都没有打开该文件夹,而是在“Recent”选项卡下打开android浏览器

我关注this question

任何提示或建议都会受到极大的赞赏!如果有任何其他代码或日志结果我应该发布,请在下面评论!

0 个答案:

没有答案
相关问题