Когда я пытаюсь сохранить изображение в InternalStorage
я получаю эту ошибку
java.lang.IllegalArgumentException: Не удается обработать uri :: content: // media / external /images / media / 221686 на android.app.DownloadManager $ Request.checkUri (DownloadManager.java:709) на android.app.DownloadManager $ Request. (DownloadManager.java:693)
MyCode
String name = getIntent().getStringExtra("name");
String filename = name+" MyImages.jpg";
// String downloadUrlOfImage = Uri.fromFile(b);
Bitmap bitmap = getBitmapFromView(view);
File direct =
new File(Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
.getAbsolutePath() + "/" + "MyImages" + "/");
if (!direct.exists()) {
direct.mkdir();
Log.d(TAG, "dir created for first time");
}
DownloadManager dm = (DownloadManager) getApplicationContext().getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Query query = new DownloadManager.Query();
Uri downloadUri = getImageUri(this, bitmap);
DownloadManager.Request request = new DownloadManager.Request(downloadUri);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE)
.setAllowedOverRoaming(false)
.setTitle(filename)
.setMimeType("image/jpeg")
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES,
File.separator + "MyImages" + File.separator + filename);
Cursor cursor = dm.query(query);
if (cursor.moveToFirst()) {
if (cursor.getCount() > 0) {
int status = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS));
if (status == DownloadManager.STATUS_SUCCESSFUL)
{
Toast.makeText(getApplicationContext(), "Image Successfully Downloaded", Toast.LENGTH_SHORT).show();
}
}
}
cursor.close();
dm.enqueue(request);