스토리지에 이미지를 쓰고 읽는 중입니다. 쓰기 작업은 성공적이지만 읽기 작업은 실패합니다. 책임있는 활동을 호출 할 때 intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
을 사용해 보았지만 도움이되지 않았습니다.파일에 쓰여진 이미지를 읽을 수 없습니다.
MediaStore.Images.Media.getBitmap(context.getContentResolver(),
Uri.parse(cursor.getString(cursor.getColumnIndex(eventDBcontract.ListofItem.columnpic))));
예외는 =
이public Bitmap getDownloadedpics(int index)
{
SQLiteDatabase db = dBcontract.getReadableDatabase();
Cursor cursor = db.query(eventDBcontract.ListofItem.tableName2, projection2, null, null, null, null, null);
cursor.moveToPosition(index);
Bitmap photo = null;
try
{
Log.d(TAG,cursor.getString(cursor.getColumnIndex(eventDBcontract.ListofItem.columnpic)));
photo = MediaStore.Images.Media.getBitmap(context.getContentResolver(),
Uri.parse(cursor.getString(cursor.getColumnIndex(eventDBcontract.ListofItem.columnpic))));
} catch (IOException e)
{
Log.e(TAG, "Can't read image");
}
Log.d(TAG, "Returned " + String.valueOf(cursor.getCount()) + " pics");
return (photo);
}
내가 사진`에서 예외를 얻을 :
java.lang.SecurityException: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{6118b35 21772:lcukerd.com.instaswipe/u0a157} (pid=21772, uid=10157) that is not exported from uid 10101
public void savepic(Bitmap pic)
{
SQLiteDatabase db = dBcontract.getWritableDatabase();
ContentValues values = new ContentValues();
FileOutputStream out = null;
try
{
File image = createImageFile();
Uri photoURI = FileProvider.getUriForFile(context, "lcukerd.com.android.fileprovider", image);
out = new FileOutputStream(image);
pic.compress(Bitmap.CompressFormat.PNG, 100, out);
values.put(eventDBcontract.ListofItem.columnpic, photoURI.toString());
db.insert(eventDBcontract.ListofItem.tableName2, null, values);
Log.i(TAG, "Pic saved " + photoURI.toString());
} catch (Exception e)
{
e.printStackTrace();
} finally
{
try
{
if (out != null)
{
out.close();
}
} catch (IOException e)
{
e.printStackTrace();
}
}
}
private File createImageFile() throws IOException
{
String EName = "Image";
File storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(EName, ".jpg", storageDir);
return image;
}
이 나는 이미지를 읽는 방법은 다음과 같습니다 이것은 내가 이미지를 작성하는 방법입니다
나는 체력이있다. 다른 유사한 질문을 cked하지만 그들은 다른 유형의 문제에 모두있는 것처럼 보입니다. 내가 해결하도록 도와 줘.
'Uri photoURI = FileProvid ...'당신은 그 파일을 쓰기 위해 그 URI를 사용하고 있지 않습니다. FileProvider를 사용하여 파일을 쓰지 않습니다. 그래서 주제에서 말하는 것은 사실이 아닙니다. – greenapps
@greenapps 그러면 "fileResolver를 작성하여 파일을 작성해야합니까?" 미안하지만 안드로이드의이 부분은 여전히 나에게 신비입니다. – user5172381
FileOutputStream을 사용하여 파일에 비트 맵을 씁니다. – greenapps