我正在嘗試使用下面的代碼(已在manifest.xml中設置權限android.permission.WRITE_EXTERNAL_STORAGE
)向SDCard寫入文件。 一旦執行nmea_file.createNewFile();
它會拋出異常與Permission Denied
。Android SD卡寫入,權限被拒絕
任何猜測爲什麼會發生這種情況?
if(!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
Log.d(TAG, "Sdcard was not mounted !!");
}
else
{
File nmea_file;
File root = Environment.getExternalStorageDirectory();
FileWriter nmea_writer = null;
try {
nmea_file = new File(root,"NMEA.txt");
if(!nmea_file.exists()) {
Log.w(TAG, "File Doesn't Exists!");
nmea_file.createNewFile();
}
nmea_writer = new FileWriter(nmea_file);
nmea_writer.append(nmea);
nmea_writer.flush();
}
catch (IOException e)
{
Log.w(TAG, "Unable to write", e);
}
finally
{
if (nmea_writer != null)
{
try
{
nmea_writer.close();
}
catch (IOException e)
{
Log.w(TAG, "Exception closing file", e);
}
}
}
}
張貼您的logcat – Falmarri 2010-12-22 06:07:19
您是否使用sharedUerId系統? – 2012-05-10 11:23:04