当我在应用程序中从图库上传图像时,但是当我选择了一些图像时,我得到了这个例外。
android.view.WindowLeaked: Activity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4133c7d8 that was originally added here
android.view.WindowManagerImpl.addView(Win
dowManagerImpl.java:152) 我没有;为什么我随机得到例外?
此代码适用于开放式图库..
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
((Activity) context).startActivityForResult(Intent.createChooser(intent,"Select Picture"), PICK_FROM_FILE);
下面的代码用于从图库中获取bimap 我
f (resultCode == RESULT_OK )
{
Uri contentUri = data.getData();
System.out.println("**************contentUri***************"+contentUri);
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String tmppath = cursor.getString(column_index);
// File abc= new File(tmppath);
System.out.println("**************tmppath***************"+tmppath);
Bitmap mBitmap = BitmapFactory.decodeFile(tmppath);
// Bitmap bitmap = BitmapFactory.decodeFile(abc);
System.out.println("**************mBitmap(gallery)***************"+mBitmap);
Court_formations objectdat =new Court_formations();
objectdat.showGalleryimage(getDialogContext(),mBitmap);
plz help
答案 0 :(得分:1)
在onactivityresult尝试使用这些代码:
Uri selectedImageUri = Uri.parse(data.getDataString());
ContentResolver cr = getContentResolver();
InputStream in = null;
try {
in = cr.openInputStream(selectedImageUri);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize=20;
Bitmap mBitmap = BitmapFactory.decodeStream(in,null,options);
Court_formations objectdat =new Court_formations();
objectdat.showGalleryimage(getDialogContext(),mBitmap);