question

NilToNil avatar image
NilToNil asked

Creating an image gallery

Hi All, I am trying to create a simple app where on button press I will able to access the image gallery and select a image. I am using ACTION_PICK intent and developing the app for Amazon kindle Fire HD. The app crashes and never reaches the onActivityResult event. My code is as below any suggestion would be appreciated. Or suggestion for any other method of accessing the gallery. onClick(View arg0){ Intent intent = new Intent(Intent.ACTION_PICK); intent.setType("image/*"); startActivityForResult(intent, RESULT_LOAD_IMAGE); } protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) { Uri selectedImage = data.getData(); String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String picturePath = cursor.getString(columnIndex); cursor.close(); ImageView imageView = (ImageView) findViewById(R.id.imgView); imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); }
fire tablet
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi NilToNil, Thank you for writing to us. Unfortunately, The problem is not reproduced in our end. The code you provided that works on Kindle Fire HD and HDX as well. I am able to get a callback on onActivityResult() with correct result code after I select an image in the Gallery in the devices. I am also able to retrieve correct value in picturePath. Could you please post the error stack trace being printed out in the logcat after the crash happens? Are you able to open the gallery? When you select an image in the gallery and comes back to the app, does crash happen that time?
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

NilToNil avatar image
NilToNil answered
Thanks, for responding back. The code works issue was the kindle was not registered :-( so it was not opening the gallery instead showing me the cloud registration page. After reading your response I registered the kindle and everything seems to be happy. Thanks for the reply,
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.