イメージをストレージに書き込んで読み込もうとしています。書き込み操作は成功しますが、読み取りは失敗します。私は責任ある活動を呼び出すときにintent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
を使用しようとしましたが、助けにはなりませんでした。 これは私がイメージを書き込む方法です:ファイルに書き込まれたイメージを読み取ることができません
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;
}
は、これは私が画像を読み取る方法です:
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);
}
私は `写真で例外を取得=
MediaStore.Images.Media.getBitmap(context.getContentResolver(),
Uri.parse(cursor.getString(cursor.getColumnIndex(eventDBcontract.ListofItem.columnpic))));
例外がある:
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
私はcheを持っています他の同様の質問ckedが、彼らはすべての問題の他のタイプのすべてのようだ。私がそれを解決するのを助ける。
'Uri photoURI = FileProvid ...'あなたは何かをファイルに書き込むためにそのURIを使用していません。 FileProviderを使用してファイルを書き込んでいません。それで、あなたが主題で言うことは成就しません。 – greenapps
@greenapps次に、 "fileResolverを書き込むためにcontentResolver"を書く必要があります。申し訳ありませんが、アンドロイドのこの部分はまだ私にとって謎です。 – user5172381
FileOutputStreamを使用してファイルにビットマップを書き込みました。 – greenapps