0

Is it possible to get File from sd card, which is picked using some 3rd apps (file manager) ?

I mean that i have activity with button open file and when user press open it shows him suggestions to use some other app to open file, and when he pick open i get back to my activity with path of that file ?

1 Answer 1

1

use this

button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult( Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE); } }); 

and add two methods in your activity

 public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { if (requestCode == SELECT_PICTURE) { Uri selectedImageUri = data.getData(); String s1 = data.getDataString(); //String s1 = selectedImageUri.getPath(); Log.e("GetPath",s1); //s1 = s1.replaceAll("file://",""); //Uri a = Uri.fromParts(s1,null,null); Log.e("OK",""+selectedImageUri); //Log.e("A",""+a); selectedImagePath = getPath(selectedImageUri); if(selectedImagePath==null && s1 != null) { selectedImagePath = s1.replaceAll("file://",""); } // selectedImagePath = getPath(a); Intent intent = new Intent(this, PhotoEditorActivity.class); intent.putExtra("path", selectedImagePath); startActivity(intent); finish(); } } } /////////////////////////////////// public String getPath(Uri uri) { try{ String[] projection = { MediaStore.Images.Media.DATA }; Log.e("OK 1",""+projection); Cursor cursor = managedQuery(uri, projection, null, null, null); Log.e("OK 2",""+cursor); if(cursor==null) { return null; } int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); Log.e("OK 3",""+column_index); cursor.moveToFirst(); Log.e("OK 4",""+cursor.getString(column_index)); return cursor.getString(column_index); } catch(Exception e) { Toast.makeText(PhotoActivity.this, "Image is too big in resolution please try again", 5).show(); return null; } } 

and add this int as class member

 private static final int SELECT_PICTURE = 1; 

enjoy coading..

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.