![](/img/trans.png)
[英]MediaStore.Images.Media.insertImage fails on Samsung tablets
[英]MediaStore.Images.Media.getBitmap fails unexpectedly
我正在構建一個可以從照片庫獲取圖像的android應用。
如果可以的話,兩個問題:
1)
Intent intent = getIntent();
Bundle extras = intent.getExtras();
String action = intent.getAction();
Uri uri = null;
// if this is from the share menu
if (Intent.ACTION_SEND.equals(action)) {
if (extras.containsKey(Intent.EXTRA_STREAM))
{
try
{
// Get resource path from intent callee
uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
我有這個uri:
content://media/external/images/media/27031
但是我的代碼在這里失敗,沒有任何信息(它只是崩潰了),沒有日志貓,沒有控制台錯誤。
try {
if (uri !=null)
{
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);
imageView.setImageBitmap(bitmap);
}
} catch (IOException e) {
e.printStackTrace();
Log.e(this.getClass().getName(), e.toString());
}
我該如何解決?
(它適用於以下網址: Uri uri = Uri.parse("content://media/external/images/media/22719");
2)我計划將所有uri保存在數據結構中。 那是推薦的方法嗎?
還是將照片保存在本地應用程序文件夾中更好?
更新資料
我認為問題在於失敗的映像位於外部SD上,而后續的映像位於本地SD上。
如何啟用來自外部SD的圖像?
一些用於從照片的“共享”操作獲取位圖的代碼...
Object obj = null;
if (Intent.ACTION_SEND.equals(_action) && _type != null) {
obj = _bundle.get("android.intent.extra.STREAM");
if( getIntent().getType().startsWith("image/") && obj != null){
if (obj instanceof android.net.Uri){ get((Uri)obj);}}
get(Uri uri){
Bitmap _bit = BitmapFactory.decodeStream(
getContentResolver().openInputStream(uri),null,options);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.