0
我上傳我的應用程序到谷歌播放後,我發現我的應用程序還沒有在我檢查過的所有設備上工作,除了我自己的...如何將文件保存在使用和不使用SD卡的不同移動設備上?
我相信問題是由於文件保存位置,我使用下面的代碼:
但是沒有SD卡的設備會發生什麼?
在logcat的我收到錯誤「無法創建目錄」
// Step 4: Set output file
mMediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO)
.toString());
outputFileName = getOutputMediaFile(MEDIA_TYPE_VIDEO).toString();
/** Create a File for saving an image or video */
private static File getOutputMediaFile(int type) {
// To be safe, you should check that the SDCard is mounted
// using Environment.getExternalStorageState() before doing this.
File mediaStorageDir = new File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES),
"Your_voice");
// 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()) {
Log.d("Your_voice_App", "failed to create directory");
return null;
}
}
// Create a media file name
String timeStamp = new SimpleDateFormat("ddMMyy_HHmmss")
.format(new Date());
File mediaFile;
if (type == MEDIA_TYPE_VIDEO) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator
+ "Your_voice" + timeStamp + ".mp4");
} else {
return null;
}
return mediaFile;
}