我正在尝试删除SD卡上的某些文件,但我的想法没用了。
我尝试过File.delete()方法,然后尝试 file.getCanonicalFile().delete() 了更多方法..我的应用程序可以删除设备存储上的文件。我已经在清单文件中定义了所需的权限,如下所示。
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
并且我也在代码中请求许可:
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
new AlertDialog.Builder(this)
.setTitle(R.string.read_storage_message)
.setPositiveButton(R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
ActivityCompat.requestPermissions(activity,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, MainActivity.READ_STORAGE_PERMISSION_ID);
}
}
)
.setNegativeButton(R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
AppKiller.kill();
}
}
).show();
}
可能是因为我正在请求READ_EXTERNAL_STORAGE和WRITE_EXTERNAL_STORAGE权限,但是在代码中我只是被READ_EXTERNAL_STORAGE授予了权限,而另一个在Android中被忽略了(WRITE_EXTERNAL_STORAGE我接受第一个后,它不会显示带有allow-deny选项的权限弹出窗口)。是不是因为它们在android中具有相同的权限级别?
有什么问题吗?
慕尼黑的夜晚无繁华
largeQ
拉莫斯之舞
相关分类