Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This works for <strong>Kitkat</strong></p> <pre><code>public class BrowsePictureActivity extends Activity{ private static final int SELECT_PICTURE = 1; private String selectedImagePath; private ImageView imageView; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.browsepicture); imageView = (ImageView)findViewById(R.id.imageView1); ((Button) findViewById(R.id.button1)) .setOnClickListener(new OnClickListener() { public void onClick(View arg0) { 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(); if (Build.VERSION.SDK_INT &lt; 19) { selectedImagePath = getPath(selectedImageUri); Bitmap bitmap = BitmapFactory.decodeFile(selectedImagePath); imageView.setImageBitmap(bitmap); } else { ParcelFileDescriptor parcelFileDescriptor; try { parcelFileDescriptor = getContentResolver().openFileDescriptor(selectedImageUri, "r"); FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor(); Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor); parcelFileDescriptor.close(); imageView.setImageBitmap(image); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } } /** * helper to retrieve the path of an image URI */ public String getPath(Uri uri) { if( uri == null ) { return null; } String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(uri, projection, null, null, null); if( cursor != null ){ int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } return uri.getPath(); } } </code></pre> <p>You need to add permission </p> <p><code>&lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;</code></p>
    singulars
    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.
 

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