setReadOnly not working

泪湿孤枕 提交于 2019-12-10 18:13:53

问题


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);

回答1:


You should define permission android.permission.MOUNT_UNMOUNT_FILESYSTEMS in AndroidManifest.xml, it means you can create file and delete file on the SDCard.



来源:https://stackoverflow.com/questions/7160182/setreadonly-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!