Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - Image does not display from built-in gallery
    primarykey
    data
    text
    <p>I am trying to use Android's built-in gallery. I am able to get the gallery and the albums, but whenever I want to display the image, the gallery straightaway directs me back to my app. I am unable to view the image despite it has been called. </p> <p>This is my code:</p> <pre><code>public class CameraTab extends Activity implements OnClickListener{ private static final int SELECT_PICTURE = 1; private String selectedImagePath; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.camera_tab); ImageButton cameraBtn = (ImageButton)findViewById(R.id.camera_btn); cameraBtn.setOnClickListener(this); ImageButton galleryBtn = (ImageButton)findViewById(R.id.gallery_btn); galleryBtn.setOnClickListener(this); } public void onClick(View v) { // TODO Auto-generated method stub if (v == this.findViewById(R.id.camera_btn)){ /// some codes here } if (v == this.findViewById(R.id.gallery_btn)){ Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE); } } public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { if (requestCode == SELECT_PICTURE) { Uri selectedImageUri = data.getData(); selectedImagePath = getPath(selectedImageUri); } } } public String getPath(Uri uri) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = managedQuery(uri, projection, null, null, null); int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } </code></pre> <p>}</p> <p>Can anyone please help me? Any help would be appreciated!! Thanks!! </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload