Trying to get image from gallery, able to open a gallery but after selecting i am getting error "E/dalvikvm( 2240): VM aborting".
This is the code i am using to get image from gallery
view.getId == @galleryButton
intent = Android::Content::Intent.new
intent.setType("image/*")
intent.setAction(Android::Content::Intent::ACTION_GET_CONTENT)
startActivityForResult(Android::Content::Intent.createChooser(intent, "select image"), SELECT_PICTURE)
def onActivityResult(requestCode, resultCode, data) if resultCode == RESULT_OK if requestCode == SELECT_PICTURE puts "after selecting image from gallery" selectedImageUri = data.getData selectedImagePath = getPath(selectedImageUri) btmapOptions = Android::Graphics::BitmapFactory::Options bm = Android::Graphics::BitmapFactory.decodeFile(selectedImagePath, btmapOptions) @imageView.setImageBitmap(bm) end end end
def getPath(uri) projection = [DATA] cursor = getContentResolver.query(uri, projection, nil, nil, nil) puts cursor column_index = cursor.getColumnIndexOrThrow(DATA) puts column_index cursor.moveToFirst cursor.getString(column_index) end
please let me know if there is any mistake in my program.
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire