Reputation: 47
i wanted to add file with specific path like that to view it as in image .. worked fine
File imgFile = new File("/storage/emulated/0/DSC_0008.JPG");
if (imgFile.exists()) {
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
ImageView myImage = (ImageView) findViewById(R.id.imageView);
myImage.setImageBitmap(myBitmap);
BUT that is not where i find my photo .. if i tried opening it manually and not from the studio
any idea how this work .. and how do i know the path that should i use to get any photo on my android
Upvotes: 0
Views: 141
Reputation:
The "/storage/emulated/0/" folder does not really exist.
It's what might be called a "symbolic link", or, in simpler terms, a reference to where the real data is stored. You'll need to find the actual physical location on your device where it is stored.
Since it's in /storage/emulated/0/DSC_0008.JPG, it's probably located in /Internal Storage/DSC_0008.JPG/. Please note that that this folder probably only contains "DSC_0008.JPG", which are very small versions of the real files.
It's possible your real files are gone forever if your SD card is irrecoverable.
As Hiren stated, you'll need a file explorer to see your directory. If you're rooted I highly suggest root explorer, otherwise ES File Explorer is a good choice.
private void chooserImage(){
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, 1888);
}
Then override a method called onActivityResult
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == getActivity().RESULT_OK && requestCode==1888){
Uri imageUri = data.getData();
String path = imageUri.getPath().toString();
File imgFile = new File(new URI(path));
//Then Here user your code
if (imgFile.exists()) {
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
ImageView myImage = (ImageView) findViewById(R.id.imageView);
myImage.setImageBitmap(myBitmap);
}
}
}
chooserImage();
to choose file and show as ImageViewYou need one more step: set permission to read SD card. Add this in AndroidManifest.xml
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Upvotes: 1
Reputation: 4667
try this
File imgFile = getOutputFile("myfileName", "imagesSubFolder");
public static File getOutputFile(String fileName, String subFolderName) {
File mediaStorageDir;
if (subFolderName == null) {
mediaStorageDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), Path.PHOTO_DIRECTORY);
} else {
mediaStorageDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), Path.PHOTO_DIRECTORY + File.separator + subFolderName);
}
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
return null;
}
} else {
try {
if (subFolderName != null) {
File noMediaFile = new File(mediaStorageDir, ".nomedia");
noMediaFile.createNewFile();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return new File(mediaStorageDir.getPath() + File.separator + fileName);
}
good luck
Upvotes: 0
Reputation: 1
Judging by the filename, DSC_0008.JPG, I'm assuming it was made with the Camera app. If that's the case your file should be in /sdcard/DCIM/Camera/
Upvotes: 0