I have used this code to start an intent to pick a picture from the tablet's gallery.
Intent pick_picture_intent = new Intent(Intent.ACTION_GET_CONTENT);
pick_picture_intent.setType("image/*");
startActivityForResult(pick_picture_intent, PICK_PICTURE);
Everything works fine, with the startActivityForResult(), having the image placed into a image view. (ONLY IN LANDSCAPE MODE), however, when I try doing the same thing in PORTRAIT MODE, it doesn't work.
Code in startActivityFroResult()
:
if(data != null && data.getData() != null) {
Uri uri = data.getData();
}
Cursor cursor = getContentResolver().query(uri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
cursor.moveToFirst();
try {
String imagePath = cursor.getString(0);
Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
ImageView imageView = new ImageView(context);
imageView.setImageBitmap(bitmap);
myLayout.addView(imageView);
} catch (Exception e) {
e.printStackTrace();
} finally {
cursor.close();
}
Why is this happening?
I was thrown this error:
android.database.sqlite.DatabaseObjectNotClosedException: Application d开发者_C百科id not close the cursor or database object that was opened here
精彩评论