我儘量讓短信日誌文件TXT,但我的設備發送一個錯誤信息像這樣不能寫在Android
07-18 10:11:33.956: E/One(1320): Could not write file /sdcard/log.txt (Permission denied)
我的代碼寫入文件
File root = Environment.getExternalStorageDirectory();
try
{
BufferedWriter fw = new BufferedWriter(new FileWriter(new File("/sdcard/log.txt"), true));
if (root.canWrite())
{
fw.newLine();
fw.write("----+ Monitoring SMS +----" + "\n");
fw.write("- Pesan Masuk "+ "\n");
fw.write(logSMS + "\n");
fw.write(" ----+||+----" + "\n");
fw.newLine();
fw.close();
}
} catch (IOException e) {
Log.e("One", "Could not write file " + e.getMessage());
}
我的應用程序的清單權限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECEIVE_MMS" />
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<uses-permission android:name="android.permission.WRITE_CALENDAR"></uses-permission>
<uses-permission android:name="android.permission.READ_CALENDAR"></uses-permission>
我找不到任何錯誤,請幫我
有關錯誤日誌,請參閱logcat。 – 2012-07-24 02:07:20
我的意思是,我找不到我的代碼中的錯誤,但logcat發送錯誤消息: 07-18 10:11:33.956:E/One(1320):無法寫入文件/sdcard/log.txt被拒絕) – adrasa 2012-07-24 02:14:16