仅适用于本地文件的Android图像选择器

Jam*_*ieH 16 android picasa image picker

我正在使用内置的Android图像选择器,如下所示:

Intent photoPickerIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
m_activity.startActivityForResult(photoPickerIntent, PHOTO_PICKER_ID);
Run Code Online (Sandbox Code Playgroud)

有没有办法限制它只显示本地可用的文件.在我的设备上,它目前正在拾取Picasa缩略图,我想要排除设备上实际不存在的所有图像.

小智 48

添加intent.putExtra(Intent.EXTRA_LOCAL_ONLY,true); 将仅允许本地文件.它将排除picasa图像.希望这可以帮助.

    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
    startActivityForResult(Intent.createChooser(intent,
            "Complete action using"), PHOTO_PICKER_ID);
Run Code Online (Sandbox Code Playgroud)

  • `EXTRA_LOCAL_ONLY`flag的唯一问题是它[仅在Honeycomb之后可用](http://developer.android.com/reference/android/content/Intent.html#EXTRA_LOCAL_ONLY).在使用之前,请务必检查API. (7认同)