Android 权限拒绝:打开未从uid 10083导出的提供程序
我正在使用listview的适配器,我想从数据库中访问字符串->将其转换为URI,并将其放入输入流->使用位图工厂解码输入流->将新位图设置为图像 以下是我的适配器代码:Android 权限拒绝:打开未从uid 10083导出的提供程序,android,android-contentprovider,permission-denied,Android,Android Contentprovider,Permission Denied,我正在使用listview的适配器,我想从数据库中访问字符串->将其转换为URI,并将其放入输入流->使用位图工厂解码输入流->将新位图设置为图像 以下是我的适配器代码: public class CardViewAdapter extends BaseAdapter { Context context; List<Note> notes; TextView cardTitleText; TextView cardDescriptionText;
public class CardViewAdapter extends BaseAdapter {
Context context;
List<Note> notes;
TextView cardTitleText;
TextView cardDescriptionText;
TextView cardDateText;
ImageView cardImage;
public CardViewAdapter(Context context, ArrayList<Note> notes) {
this.context = context;
this.notes = notes;
}
@Override
public int getCount() {
return notes.size();
}
@Override
public Object getItem(int position) {
return notes.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.card_view, parent, false);
cardTitleText = (TextView) view.findViewById(R.id.titleTextCardView);
cardDescriptionText = (TextView) view.findViewById(R.id.descriptionTextCardView);
cardDateText = (TextView) view.findViewById(R.id.dateTextCardView);
cardImage = (ImageView) view.findViewById(R.id.cardImage);
Note note = notes.get(position);
cardTitleText.setText(note.getTitle());
cardDescriptionText.setText(note.getDescription());
cardDateText.setText(note.getDate());
if(note.getImagePath() != null) {
try {
InputStream inputStream = getContentResolver().openInputStream(Uri.parse(note.getImagePath()));
databaseImage = BitmapFactory.decodeStream(inputStream);
cardImage.setImageBitmap(databaseImage);
inputStream.close();
} catch (IOException exception) { exception.printStackTrace(); }
}
return view;
}
}
以下是错误:
10-16 20:21:18.566: E/AndroidRuntime(11501): FATAL EXCEPTION: main
10-16 20:21:18.566: E/AndroidRuntime(11501): Process: com.meetz.personaljourney, PID: 11501
10-16 20:21:18.566: E/AndroidRuntime(11501): java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.photos.contentprovider.MediaContentProvider from ProcessRecord{19ad093 11501:com.meetz.personaljourney/u0a102} (pid=11501, uid=10102) that is not exported from uid 10083
我在stackoverflow上阅读了关于这个错误的每一个线程,但没有一个我尝试过的有效。我没有使用任何自定义提供程序,因此我的android_manifest.xml中没有提供程序。另外,我认为“getContentResolver()”会返回错误,但我不知道为什么
------------------------编辑------------------------
以下是获取图像并将其存储在数据库中的代码:
addNote.getPopupImage().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath();
Uri uri = Uri.parse(path);
photoPickerIntent.setDataAndType(uri, "image/*");
startActivityForResult(photoPickerIntent, AddNote.IMAGE_GALLERY);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == AddNote.IMAGE_GALLERY) {
Uri photoLocation = data.getData();
addNote.setPhotoPath(photoLocation.toString());
try {
InputStream inputStream = getContentResolver().openInputStream(photoLocation);
selectedImage = BitmapFactory.decodeStream(inputStream);
addNote.setPopupImage(selectedImage);
inputStream.close();
} catch (IOException exception) {
exception.printStackTrace();
}
}
}如果有任何误解,请询问,我会尽力帮助。您试图打开的Uri是SD卡分区上的文件吗?如果是,则可能需要“读取外部存储”权限。从何处获取图像路径?您可以显示该代码吗?特别是,如果您正在保存一个
Uri
您从ACTION\u PICK
或ACTION\u GET\u CONTENT
获取的一段时间以前的内容,则这将不起作用,因为您使用这些Uri
值的权限将失效。我已经在使用premission来读取和写入存储。我从图片中获取Uri,将其转换为字符串并将其保存到数据库中。当我重新打开我的应用程序时,我试图获取该字符串,再次将其解析为URI,然后使用相同的URI作为路径来访问相同的图像并显示它。基本上,我试图从数据库中获取保存的路径,以检索保存到其中的相同图片,从而显示非常相同的图片。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == AddNote.IMAGE_GALLERY) {
Uri photoLocation = data.getData();
addNote.setPhotoPath(photoLocation.toString());
try {
InputStream inputStream = getContentResolver().openInputStream(photoLocation);
selectedImage = BitmapFactory.decodeStream(inputStream);
addNote.setPopupImage(selectedImage);
inputStream.close();
} catch (IOException exception) {
exception.printStackTrace();
}
}
singleNote = new Note(popupTitle.getText().toString(),
popupDescription.getText().toString(),
new SimpleDateFormat("dd-MM-yyyy").format(new Date()),
photoPath != null ? photoPath : "");
notes.add(singleNote);
mainDatabase.addNewNote(singleNote);