4
我試圖將圖像插入到Android手機的手機內存中。我收到以下例外情況,但是當我嘗試使用EXTERNAL_CONTENT_URI
時沒有問題,但如果SD卡不存在,我想寫入手機內存。將圖像插入內部存儲器
任何人請給我一個解決方案嗎?提前致謝。
#我的代碼
#ContentValues values = new ContentValues(2);
values.put(Media.DISPLAY_NAME, "My Bitmap");
values.put(Media.MIME_TYPE, "image/jpeg");
Uri uri = getContentResolver().insert(Media.INTERNAL_CONTENT_URI,values);
//Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI,values);
OutputStream outStream = getContentResolver().openOutputStream(uri);
b.compress(Bitmap.CompressFormat.JPEG, 50, outStream);
outStream.close();
###################################
11-03 20:02:48.526: ERROR/DatabaseUtils(167): java.lang.UnsupportedOperationException: Writing to internal storage is not supported.
11-03 20:02:48.526: ERROR/DatabaseUtils(167): at com.android.providers.media.MediaProvider.generateFileName(MediaProvider.java:1646)
11-03 20:02:48.526: ERROR/DatabaseUtils(167): at com.android.providers.media.MediaProvider.ensureFile(MediaProvider.java:1337)
11-03 20:02:48.526: ERROR/DatabaseUtils(167): at com.android.providers.media.MediaProvider.insertInternal(MediaProvider.java:1413)
11-03 20:02:48.526: ERROR/DatabaseUtils(167): at com.android.providers.media.MediaProvider.insert(MediaProvider.java:1381)
11-03 20:02:48.526: ERROR/DatabaseUtils(167): at android.content.ContentProvider$Transport.insert(ContentProvider.java:150)
11-03 20:02:48.526: ERROR/DatabaseUtils(167): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:140)
11-03 20:02:48.526: ERROR/DatabaseUtils(167): at android.os.Binder.execTransact(Binder.java:287)
11-03 20:02:48.526: ERROR/DatabaseUtils(167): at dalvik.system.NativeStart.run(Native Method)
你有沒有找到解決辦法? – 2015-01-13 15:21:25