我创建/保存在SD卡上的文件。 这是代码:
File sdDir = Environment.getExternalStorageDirectory();
public void btnsave_clicked(View v) throws FileNotFoundException, IOException{
File f;
f=new File(sdDir, "deposit.dma");
if(!f.exists())
f.createNewFile();
...
}
但是,当我按一下按钮,它会抛出“拒绝的权限”。 对于添加使用许可权,不要问我。
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
我已经在清单中添加这一点。
我该怎么办? logcat的信息:
10-19 20:25:14.681: E/AndroidRuntime(29016): FATAL EXCEPTION: main
10-19 20:25:14.681: E/AndroidRuntime(29016): java.lang.IllegalStateException: Could not execute method of the activity
10-19 20:25:14.681: E/AndroidRuntime(29016): at android.view.View$1.onClick(View.java:2168)
10-19 20:25:14.681: E/AndroidRuntime(29016): at android.view.View.performClick(View.java:2552)
10-19 20:25:14.681: E/AndroidRuntime(29016): at android.view.View$PerformClick.run(View.java:9229)
10-19 20:25:14.681: E/AndroidRuntime(29016): at android.os.Handler.handleCallback(Handler.java:587)
10-19 20:25:14.681: E/AndroidRuntime(29016): at android.os.Handler.dispatchMessage(Handler.java:92)
10-19 20:25:14.681: E/AndroidRuntime(29016): at android.os.Looper.loop(Looper.java:130)
10-19 20:25:14.681: E/AndroidRuntime(29016): at android.app.ActivityThread.main(ActivityThread.java:3701)
10-19 20:25:14.681: E/AndroidRuntime(29016): at java.lang.reflect.Method.invokeNative(Native Method)
10-19 20:25:14.681: E/AndroidRuntime(29016): at java.lang.reflect.Method.invoke(Method.java:507)
10-19 20:25:14.681: E/AndroidRuntime(29016): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
10-19 20:25:14.681: E/AndroidRuntime(29016): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
10-19 20:25:14.681: E/AndroidRuntime(29016): at dalvik.system.NativeStart.main(Native Method)
10-19 20:25:14.681: E/AndroidRuntime(29016): Caused by: java.lang.reflect.InvocationTargetException
10-19 20:25:14.681: E/AndroidRuntime(29016): at java.lang.reflect.Method.invokeNative(Native Method)
10-19 20:25:14.681: E/AndroidRuntime(29016): at java.lang.reflect.Method.invoke(Method.java:507)
10-19 20:25:14.681: E/AndroidRuntime(29016): at android.view.View$1.onClick(View.java:2163)
10-19 20:25:14.681: E/AndroidRuntime(29016): ... 11 more
10-19 20:25:14.681: E/AndroidRuntime(29016): Caused by: java.io.IOException: Permission denied
10-19 20:25:14.681: E/AndroidRuntime(29016): at java.io.File.createNewFileImpl(Native Method)
10-19 20:25:14.681: E/AndroidRuntime(29016): at java.io.File.createNewFile(File.java:1257)
10-19 20:25:14.681: E/AndroidRuntime(29016): at org.brotheroftux.depositmaster.MainActivity.btnsave_clicked(MainActivity.java:43)
10-19 20:25:14.681: E/AndroidRuntime(29016): ... 14 more