在我的应用程序中,当用户在'ImageView'上按下时,我创建一个选择器意图,将促进用户更改图片。覆盖选择器意图行为
这里是我使用的代码时,在ImageView的用户点击
userProfileIMG.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
photoPickerIntent.setType("image/*");
Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePhotoIntent.resolveActivity(getPackageManager()) != null)
{
try
{
photoFile = Create_ImageFile();
}
catch (Exception e)
{
Log.e("file", e.toString());
}
if (photoFile != null)
{
takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile.getAbsoluteFile()));
}
}
String pickTitle = getString(R.string.select_or_take_new_picture);
Intent chooserIntent = Intent.createChooser(photoPickerIntent, pickTitle);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{takePhotoIntent});
startActivityForResult(chooserIntent, ACTIVITY_SELECT_PICTURE);
}
});
这是结果
我的问题是,当上“画廊”用户请选择6.0上的图像它的安全例外,因为我想请求<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
只有当他按'画廊'有什么方法来覆盖用户按'画廊'时的行为,以便我请求权限,然后如果他被授予我让他继续去画廊否则我否认他? 或者我必须手动构建相同的选择器,而不取决于系统为我构建对话框?
相机需要许可。您需要请求动态访问摄像头的权限。 –
更好的方法是在用户进入配置文件页面时请求权限。仅在授予Camera和EXTERNAL_STORAGE权限时才显示对话框以选择选项。 –
@RaguSwaminathan我不能访问相机,我让相机自己拍照,并且不需要许可。 实际上,这是您让系统应用程序为您完成工作的权限的方式。 更多https://developer.android.com/training/permissions/best-practices.html –