setReadOnly 不起作用
我正在使用 setReadOnly
方法将我的应用程序目录存储在我的 SD 卡上“只读”。然而,即使我在清单中为应用程序提供了 android.permission.WRITE_EXTERNAL_STORAGE
权限,调用此方法时也会返回“false”。
这是我的代码:
is.close();
fos.close();
Decompress d = new Decompress(productDirectory + "/downloadedfile.zip", productDirectory + "/unzipped/");
d.unzip();
File zipfile = new File(productDirectory + "/downloadedfile.zip");
zipfile.delete();
productDirectory = new File(Environment.getExternalStorageDirectory().toString() + "/zipfiledemo");
boolean isWriteLocked = productDirectory.setReadOnly();
Log.v("Writing access locked",">>>>>>>>>>>>>>>>>>>" + isWriteLocked);
I am using setReadOnly
method to make my app's directory stored on my SD card 'Read-only'. However this method when called is returning 'false' even though I have provided the app with android.permission.WRITE_EXTERNAL_STORAGE
permission in the manifest.
Here's my code :
is.close();
fos.close();
Decompress d = new Decompress(productDirectory + "/downloadedfile.zip", productDirectory + "/unzipped/");
d.unzip();
File zipfile = new File(productDirectory + "/downloadedfile.zip");
zipfile.delete();
productDirectory = new File(Environment.getExternalStorageDirectory().toString() + "/zipfiledemo");
boolean isWriteLocked = productDirectory.setReadOnly();
Log.v("Writing access locked",">>>>>>>>>>>>>>>>>>>" + isWriteLocked);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该在
AndroidManifest.xml
中定义权限android.permission.MOUNT_UNMOUNT_FILESYSTEMS
,这意味着您可以在SDCard上创建文件和删除文件。You should define permission
android.permission.MOUNT_UNMOUNT_FILESYSTEMS
inAndroidManifest.xml
, it means you can create file and delete file on the SDCard.