简体   繁体   中英

Is it possible to delete a drawable folder using java code?

I'm wondering if there's a way to delete a folder inside res in an Android app, via java code, in an activity.

Imagine I have some files in drawable-nodpi in a paid app which has a "license checker" or "payment checker", what I want is that if that "license" is not valid, it would delete the files inside that folder (drawable-nodpi) and just that folder, using some lines of code in my activity.

Thanks in advance for any help or info.

I'm wondering if there's a way to delete a folder inside res in an Android app, via java code, in an activity.

No. Resources and assets are read-only at runtime.

The quick answer is no.

For your problem however, you could just stop displaying the drawables in your application. That would be super easy to do. The drawables would still be in the res/drawable folder, but they just wouldn't be displaying anymore.

Another thing you could do is to download those files at run-time after the license-check has been done, but such a solution would involve more work on your end.

Yes, it is possible, however what you must consider is how the actual security of the Android OS works.

Consider the following: On standard devices(no root access) Android's security relies in great part on the user/group linux's system, which states that you may only have certain permissions if you belong to a user group which specific kind of access.

In Android Applications belong to their "own" user, and therefore may not access any other file, or process that might belong to anything else.

If you would like to delete specific directories, files, etc.. with java code, you will need to become root, or use an engineering build of your specific Android distribution, and grant your app access by changing it to the root user group.

Finally consider, is android intended to work this way? The answer is no, as it would be an exploitable breach in the system, allowing apps to perform this kind of tasks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM