Clear another applications cache

眉间皱痕 提交于 2019-12-11 11:45:02

问题


I´ve been reading around here about cleaning another applications cahce-memory, and I´ve also tried coding my own app. The result I´ve got, is that with Androids current securitylayer, it´s not possible.

But, there is currently many cache-cleaner applications out there on the Market (Google Play)?

When I started my application which I gave the android.permission.DELETE_CACHE_FILES permission, the LogCat printed

Not granting permission android.permission.DELETE_CACHE_FILES to package <MY_PACKAGE_NAME> (protectionLevel=3 flags=0x8be46)

After some research I found out that 3:rd party apps would not be granted permissions with protectionLevel=3 so, I encounter a java.lang.SecurityException whenever I try to delete another application cache (logically)

My question is therefor: "How is these applications on Google Play permitted and able to delete other applications cache?"

Sorry for my bad English, not a native speaker


回答1:


You can only do this if the device is rooted and your application has super user rights.




回答2:


Let me tell you how these apps achieve this.

Some android classes have methods which are private(@hidden) to user by default. We cannot access them directly. but you have a better approach to use Reflection.

Add permission.

<uses-permission android:name="android.permission.CLEAR_APP_CACHE"/>

And follow these answers

https://stackoverflow.com/a/17334600/3496570

https://stackoverflow.com/a/14509140/3496570

And don't forget to create a package name android.content.pm and add IPackageDataObserver.aidl to package . Then you are good to go.



来源:https://stackoverflow.com/questions/14047895/clear-another-applications-cache

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