Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMahmoud Tokura
789 PointsCant find File Path
Im using genymotion as my emulator, when i run my app i get this "File: file:///storage/emulated/0/Pictures/Ribbit/IMG_20150509_1202.jpg in log"
but i can find this file path i my emulator file manger.
see my code below.
private Uri getOutPutMediaFileUri(int mediaType) { // To be safe, you should check that the SDCard is mounted // using Environment.getExternalStorageState() before doing this. if(isExtenalStorageAvailable()){ //Get Uri;
//1. get the external storage directory
String appName = MainActivity.this.getString(R.string.app_name);
File mediaStorageDir = new File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),appName);
//2. Create our subdirectory
if(! mediaStorageDir.exists()){
if(! mediaStorageDir.mkdirs()){
Log.e(TAG, "Failed to create directory.");
return null;
}
}
//3. Create a file name
//4. Create the file
File mediaFile;
Date now = new Date();
String timestamp = new SimpleDateFormat("yyyyMMdd_HHss",Locale.US).format(now);
String path=mediaStorageDir.getPath() + File.separator;
if(mediaType == MEDIA_TYPE_IMAGE){
mediaFile = new File(path + "IMG_" + timestamp + ".jpg");
}else if(mediaType == MEDIA_TYPE_VIDEO){
mediaFile = new File(path + "VID_" + timestamp + ".mp4");
}else {
return null;
}
Log.d(TAG,"File: " + Uri.fromFile(mediaFile));
//5. Return the files Uri
return Uri.fromFile(mediaFile);
}
else {
return null;
}
}
Daniel Vido
4,824 PointsHi, What was the solution? :) I have the same issue.
Mahmoud Tokura
789 PointsMahmoud Tokura
789 PointsFound the solution, was a bit annoying but at least i works.