这是代码
public class RSSReader extends IntentService{
protected void onHandleIntent(Intent intent) {
try {
File myFile = new File(Environment.getExternalStorageDirectory()+"rss.txt");
FileInputStream fIn = new FileInputStream(myFile);
BufferedReader myReader = new BufferedReader(
new InputStreamReader(fIn));
String aDataRow = "";
String aBuffer = "";
result2 = myReader.readLine();
myReader.close();
Log.i(TAG,"File read.");
} catch (Exception e) {
...
}
if (...) {
sendNotification("There are new notices.");
Log.i(TAG, "New notice.");
result2 =result;
try {
File file = new File(Environment.getExternalStorageDirectory()+File.separator+"rss.txt");
file.mkdirs();
file.createNewFile();
FileOutputStream fOut = new FileOutputStream(file);
OutputStreamWriter myOutWriter =
new OutputStreamWriter(fOut);
myOutWriter.append(result2);
myOutWriter.close();
fOut.close();
Log.i(TAG,"File created");
}catch (Exception e){
...
}
}else{
...
}
SampleAlarmReceiver.completeWakefulIntent(intent);
}
...
}
此服务由AlarmManager启动。我正在尝试在SD卡上创建一个文件,并在AlarmManager第二次触发时读取它。这甚至可能吗?现在我收到错误说“打开失败:权限被拒绝:EACCES” 有人可以帮我吗?谢谢。