我正在学习Android。我想从图库中加载图片..但有些事情是错误的
请帮忙....
它与我的enter link description here相似
这是我的错误代码我认为这意味着“我无法触摸我的uri”,但我检查了我的清单
这是错误代码。
引起:java.lang.SecurityException:Uid 10087没有权限uri 0 @ content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%在Android.app.Parcel.readException(Parcel.java:1637)的android.app.Aardor.ProartA活动中的android.O.Parcel.readException(Parcel.java:1637)的2Ffile%2F116 / ORIGINAL / NONE / 1817194500(ActivityManagerNative。 java:3101)在android.app.Instrumentation.execStartActivity(Instrumentation.java:1518)android.app.Activity.startActivityForResult(Activity.java:4225)android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java) :757)在android.app.Activity.startActivityForResult(Activity.java:4183)的android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:744)at com.example.z2_sooodt.syslet_2018_summer.pre_startActivity.onActivityResult( pre_startActivity.java:220)在android.app.Activity.dispatchActivityResult(Activity.java:6932)
这是我的Manifest的一部分
<manifest...
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" android:required="true"/>
.... </application
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.z2_sooodt.syslet_2018_summer.filepaths"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>
</application>
代码的一部分
private Uri mImage;
private ImageView iview;
private String absoultePath;
private static final int PICK_FROM_CAMERA = 0;
private static final int PICK_FROM_ALBUM = 1;
private static final int CROP_FROM_IMAGE = 2;
public int FuckingFLAG;
private String[] permissions = {Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA};
@Override
public void onClick(View view) {
final DialogInterface.OnClickListener cameraListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(android.provider.MediaStore.Images.Media.CONTENT_TYPE);
intent.setData(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, PICK_FROM_ALBUM);
}
};
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) {
return;
}
if(requestCode == PICK_FROM_ALBUM) {
if (data == null)
return;
mImage = data.getData();
Intent cropPictureIntent = new Intent("com.android.camera.action.CROP");
cropPictureIntent.setDataAndType(mImage, "image/*");
cropPictureIntent.putExtra("output", mImage);
cropPictureIntent.putExtra("outputX", 256);
cropPictureIntent.putExtra("outputY", 256);
cropPictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
cropPictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
startActivityForResult(cropPictureIntent, CROP_FROM_IMAGE); /*This is the Error
(at com.example.z2_sooodt.syslet_2018_summer.pre_startActivity.onActivityResult(pre_startActivity.java:220) ) **///
}
什么是模拟器或手机API?您是否尝试通过手机偏好设置/应用和通知/ YourApp /权限为您的APP授予权限?