그냥 적어도 부분적인 대답으로 업데이트하겠다고 생각했습니다. 적어도 내 문제 중 일부는 내 Razr Maxx에서 디버그 모드로 테스트하는 것과 관련이 있습니다. USB 디버깅을 통해 연결되면 다음과 같이 새 파일을 만드는 호출이 실패합니다.
06-06 10 : 04 : 30.512 : W/System.err (2583) : java.io.IOException : open failed : EACCES (사용 권한이 거부 됨) 06-06 10 : 04 : 30.512 : W/System.err (2583) : java.io.File.createNewFile (File.java:940)
독립 실행 형 응용 프로그램을 실행할 때 내 장치 또는 에뮬레이터에서 다음 모든 예상대로 작동합니다. 이것이 Razr Maxx 또는 다른 문제와 관련이 있는지 확실하지 않은가요? 노력
내 코드 (: Write a file in external storage in Android에서)입니다
private void writeToSDFile(){
// Find the root of the external storage.
// See http://developer.android.com/guide/topics/data/data- storage.html#filesExternal
File root = android.os.Environment.getExternalStorageDirectory();
mStatusTV.append("\nExternal file system root: "+root);
// See https://stackoverflow.com/questions/3551821/android-write-to-sd-card-folder
File dir = new File (root.getAbsolutePath() + "/download");
dir.mkdirs();
File file = new File(dir, "myData.txt");
try {
file.createNewFile();
FileOutputStream f = new FileOutputStream(file);
PrintWriter pw = new PrintWriter(f);
pw.println("Hi , How are you");
pw.println("Hello");
pw.flush();
pw.close();
f.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.i(TAG, "******* File not found. Did you" +
" add a WRITE_EXTERNAL_STORAGE permission to the manifest?");
mStatusTV.append("Write File 1: " + e.getMessage());
} catch (IOException e) {
e.printStackTrace();
mStatusTV.append("Write File 2: " + e.getMessage());
}
mStatusTV.append("\n\nFile written to "+file);
}