How to get the phone's cache

Source: Internet
Author: User

1, the mobile phone in the cache is generally placed in the mobile phone data/data/project/cache, the cache file is not readable and not writable, so can not be directly obtained 2, in the source to find Mpm.getpackagesizeinfo (package name, Mstatsobserver  ); 3, Getpackagesizeinfo method has been hidden, can only use reflection to obtain: Need to import these two aidl files

Ipackagestatsobserver.aidl and Packagestats.aidl

1??                        Gets the Packagemanager Manager object, public static void Getcachesize (final Activity context, String packname,final     Ongetcachesizelistener listener) {Packagemanager pm = Context.getpackagemanager (); 2?? Use reflection//1. Class Class<?     Extends packagemanager> clazz = Pm.getclass (); 2. Method method = Clazz.getdeclaredmethod ("Getpackagesizeinfo", new class[] {String.class,ipackagestatsobserv       Er.class}); 3.objpm            has acquired the Task Manager  //in order to get to the callback, define an interface       Ipackagestatsobserver.stub mstub = new Ipackagestatsobserver.stub () {       @Override      public void ongetstatscompleted (Packagestats pstats, Boolean succeeded)       throws RemoteException {     //callback result      final long CacheSize = pstats.cachesize;                 //because the UI interface has been modified, it cannot be run in a child thread , create a UI thread that modifies      context.runonuithread (new Runnable () {     in the main thread   @Override      public void Run () {     //TODO Auto-generated method Stub     listener.getcachesize (cacheSize);//callback The result to the user            }});      //4. Invoke method.invoke (PM, New Object[]{pacKname,mstub}); }     3?? Define an interface        public class Getappcachemessageutils {
public interface ongetcachesizelistener{
void Getcachesize (Long cacheSize);}

How to get the phone's cache

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.