我必须将参数从MyActivity.class传递给TestService.class.MyActivity是一个Activity类,TestService是我用来发送消息的服务.我必须将参数从Activity传递给Service,但是当我Intent i = getIntent();在服务类中调用时,我得到一个错误getIntent()是未定义的.
那么,如何将参数从我的Activity发送到服务?
在外部SD卡中写入文件时,我收到错误EACCESS权限被拒绝.我已经设置了权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
但是当我读取文件时,我已成功读取它但无法写入文件.我用于在SD卡中写入文件的代码是:
String path="mnt/extsd/Test";
try{
File myFile = new File(path, "Hello.txt"); //device.txt
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
myOutWriter.append(txtData.getText());
myOutWriter.close();
fOut.close();
Toast.makeText(getBaseContext(),"Done writing SD "+myFile.getPath(),Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(),Toast.LENGTH_SHORT).show();
System.out.println("Hello"+e.getMessage());
}
}
Run Code Online (Sandbox Code Playgroud)
外部存储卡的路径是mnt/extsd/.这就是为什么我无法使用Environment.getExternalStorageDirectory().getAbsolutePath()哪个给我一个路径mnt/sdcard,这条路径是我的平板电脑中的内部存储路径.请说明为什么会这样,我该如何解决这个问题