Android calls the system method to obtain application information, such as the cache size.

Source: Internet
Author: User

Android calls the system method to obtain application information, such as the cache size.

1. android has a way to get the application cache, but it is a little troublesome to use. However, our applications sometimes need to let users know the size of the cache, so that users can promptly clean up the cache.

Run the Code directly. The demo is created using android studio. Http://pan.baidu.com/s/1sjkONzn

 

2. The code is just a method.

 

private void getPackageSizeInfo(final String mPackageName) {    try {        Method getPackageSizeInfo = getPackageManager().getClass().getMethod(                getPackageSizeInfo, String.class, IPackageStatsObserver.class);        getPackageSizeInfo.invoke(getPackageManager(), mPackageName, new IPackageStatsObserver.Stub() {            @Override            public void onGetStatsCompleted(final PackageStats pStats, boolean succeeded)                    throws RemoteException {                runOnUiThread(new Runnable() {                    @Override                    public void run() {                        textView.setText(qq file code  + Formatter.formatFileSize(getApplication(), pStats.codeSize) +                                         + data size  + Formatter.formatFileSize(getApplication(), pStats.codeSize) +                                         + cache size  + Formatter.formatFileSize(getApplication(), pStats.cacheSize) +                         );                        Log.e(content, pStats.toString());                    }                });            }        });    } catch (NoSuchMethodException e) {        e.printStackTrace();    } catch (IllegalAccessException e) {        e.printStackTrace();    } catch (InvocationTargetException e) {        e.printStackTrace();    }}
Permission required

 

 

 

 

3. the following uses qq as an example.

 

getPackageSizeInfo(com.tencent.mobileqq);

 

 

 

Related Article

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.