Created
November 9, 2016 17:52
-
-
Save iamcxa/3692e6ba26e817ad6b42c5d6b7d3713f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Create a File for saving an image or video */ | |
private File getOutputMediaFile(){ | |
// To be safe, you should check that the SDCard is mounted | |
// using Environment.getExternalStorageState() before doing this. | |
// p.s: MODIFY THE PATH YOU WANT YOUR IMAGE TO STORE HERE | |
// 嗨嗨如果你想改儲存路徑記得改這邊 | |
// for example, you can just using this way to save image into the root of sdcard | |
// File mediaStorageDir = new File(Environment.getExternalStorageDirectory().toString()); | |
File mediaStorageDir = new File(Environment.getExternalStorageDirectory() | |
+ "/Android/data/" | |
+ getApplicationContext().getPackageName() | |
+ "/Files"); | |
// This location works best if you want the created images to be shared | |
// between applications and persist after your app has been uninstalled. | |
// Create the storage directory if it does not exist | |
if (! mediaStorageDir.exists()){ | |
if (! mediaStorageDir.mkdirs()){ | |
return null; | |
} | |
} | |
// Create a media file name | |
String timeStamp = new SimpleDateFormat("ddMMyyyy_HHmm").format(new Date()); | |
File mediaFile; | |
String mImageName="MI_"+ timeStamp +".jpg"; | |
mediaFile = new File(mediaStorageDir.getPath() + File.separator + mImageName); | |
return mediaFile; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment