我正在尝试允许用户从图库上传图片。
点击按钮arr.forEach(function(item, i) {
arr[i] = {somethingElse: 1} //using index, change the reference in array
});
-
pickFromGallery
onActivityResult实现如此 -
pickFromGallery.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (Build.VERSION.SDK_INT < 19) {
Intent intent = new Intent();
intent.setType("image/jpeg");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), 2124);
} else {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
intent.setType("image/jpeg");
startActivityForResult(intent, 1);
}
}
});
我得到例外 -
if (requestCode == 1) {
Uri originalUri = null;
if (Build.VERSION.SDK_INT < 19) {
originalUri = data.getData();
} else {
originalUri = data.getData();
final int takeFlags = data.getFlags()
& (Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
try {
getContentResolver().takePersistableUriPermission(originalUri, takeFlags);
}
catch (SecurityException e){
e.printStackTrace();
}
}
仅限Xiomi Mi(Android版本5.0.2)
我的清单 -
11-02 19:17:08.848 24468-24468/com.tinystep.app W/System.err: java.lang.SecurityException: No persistable permission grants found for UID 10268 and Uri 0 @ file:///storage/emulated/0/DCIM/Camera/IMG_20150612_222143.jpg
我看过How to persist permission in android API 19 (KitKat)?和No permission for UID to access URI error on Android Application,但那里提到的解决方案对我没用。
任何帮助都会受到高度赞赏,我已经坚持了一段时间。