Showing posts with label cache memory. Show all posts
Showing posts with label cache memory. Show all posts

Tuesday, 26 July 2016

AppMaster Lite - Solution for your mobile memory management


If you’re looking for some nice application tool for your android mobile then AppMaster Lite is here. Manage your apps, storage management, clear cache , move apps to SD and much more with Lite size app. This app contains NO ADS.

1. Are you facing Internal memory full issue?
2. Are you unable to clear unwanted cache data of your mobile?
3. Do you want to store / move your apps in to External SD card?
4. Do you have the clear listings of Installed apps and System apps?

If you’re facing above problems in your android mobile then AppMaster Lite is one solution.






1. View Storage uses in Android 


This is the landing screen of app, where you can see the both internal and SD card memory uses in Pie chart representation. Chart value shows the percentage uses of memory. Below of charts you can see the numerical value of used memory.




2. Clear cache data of Android mobile

This option is available at the bottom of Storage screen tab. Cache memory is the garbage data of the applications which are not at all useful. If you don’t delete cache data at regular intervals then it will full the internal memory and your mobile will face ‘Insufficient Storage’ Message during downloading any app form PlayStore. Cache data also slow down the mobile speed.
If you want to clear cache data then click on given option this will navigate to internal memory setting where you can clear cache by following the guides. Since android os has put restriction to third party app to not clear cache data directly so user should manually clear the cache data (After Marshmallow version).

3. Move apps to SD card


This screen only shows the list of movable apps. All the installed apps can’t be moved to SD card because of properties set in the application by developer. Once you click move icon it will open the storage option and you can move you applications to free some internal storage. 


4. Uninstall application in one tap 


Installed apps contains the list of application which are installed by users. List also shows the occupied memory by app. Delete button uninstalls the app.


5. View only System apps in android


System apps list only contains the already installed apps. User can’t uninstalled the these apps. For more information tap on info icon.


6. Other features in AppMaster Lite

Rate us, share apps, About and other useful features also has been added in side navigation.

7. No Ads

This app doesn’t contain any ads. So users don’t get any disturbance in using time. 
This is an awesome too to manage memory in android mobile and speed up the process speed. Download for free.

Please feel free to comment for any clarification or suggestion.



Monday, 20 June 2016

Android get cache size, data size, apk size for all installed application

I had to make one application which should show the list of installed applications and their size occupied in internal memory, i struggled a lot to find the complete solution at one place. Here I ‘m sharing the full solution which i achieved. 

We can’t get the cache size directly by using PackageManager. We need to use Java Reflection and AIDL  to achieve this. 

Steps to get get cache size, data size and apk size
1. Create AIDL package and add files.
2. Create Class AppDetails.java to get installed package list.
3. Create class by extending IPackageStatsObserver.Stub.
4. Use getPackageSizeInfo method to get data.
Android get app data size using AIDL

1. Create AIDL package and add files.
Create package android.content.pm inside src/main and add the below two files.
IPackageStatsObserver.aidl
package android.content.pm;

import android.content.pm.PackageStats;
/**
 * API for package data change related callbacks from the Package Manager.
 * Some usage scenarios include deletion of cache directory, generate
 * statistics related to code, data, cache usage(TODO)
 * {@hide}
 */
oneway interface IPackageStatsObserver {

    void onGetStatsCompleted(in PackageStats pStats, boolean succeeded);
}

PackageStats.aidl
package android.content.pm;
parcelable PackageStats;


Here is the snap for my project structure:




2. Create Class AppDetails.java to get installed package list.

AppDetails.java
import android.app.Activity;
import android.content.pm.PackageInfo;
import android.graphics.drawable.Drawable;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by mukeshk on 6/17/2016.
 */

    public class AppDetails {
        Activity mActivity;
        public ArrayList<PackageInfoStruct> res new ArrayList<PackageInfoStruct>();
        public ListView list;
        public String app_labels[];

        public AppDetails(Activity mActivity) {
            this.mActivity = mActivity;

        }

        public ArrayList<PackageInfoStruct> getPackages() {
            ArrayList<PackageInfoStruct> apps = getInstalledApps(false);
            final int max = apps.size();
            for (int i = 0; i < max; i++) {
                apps.get(i);
            }
            return apps;
        }

        private ArrayList<PackageInfoStruct> getInstalledApps(boolean getSysPackages) {

            List<PackageInfo> packs = mActivity.getPackageManager()
                    .getInstalledPackages(0);
            try {
                app_labels new String[packs.size()];
            } catch (Exception e) {
                Toast.makeText(mActivity.getApplicationContext(), e.getMessage(),
                        Toast.LENGTH_SHORT).show();
            }
            for (int i = 0; i < packs.size(); i++) {
                PackageInfo p = packs.get(i);
                if ((!getSysPackages) && (p.versionName == null)) {
                    continue;
                }
                PackageInfoStruct newInfo = new PackageInfoStruct();
                newInfo.appname = p.applicationInfo.loadLabel(
                        mActivity.getPackageManager()).toString();
                newInfo.pname = p.packageName;
                newInfo.datadir = p.applicationInfo.dataDir;
                newInfo.versionName = p.versionName;
                newInfo.versionCode = p.versionCode;
                newInfo.icon = p.applicationInfo.loadIcon(mActivity
                        .getPackageManager());
                res.add(newInfo);

                app_labels[i] = newInfo.appname;
            }
            return res;
        }

        class PackageInfoStruct {
            String appname "";
            String pname "";
            String versionName "";
            int versionCode 0;
            Drawable icon;
            String datadir "";
        }

3. Create class by extending IPackageStatsObserver.Stub.
 I have created separate class StorageInformation which will have getpackageSize method to execute the code to calculate cache and another data. One inner class cachePackState have to create by extending IPackageStatsObserver.Stub. Here we have to onGetStatsCompleted method. Here is the complete code: 

StorageInformation.java

import android.app.Activity;
import android.content.Context;
import android.content.pm.IPackageStatsObserver;
import android.content.pm.PackageManager;
import android.content.pm.PackageStats;
import android.os.RemoteException;
import android.util.Log;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;

/**
 * This class will perform data operation
 */
public class StorageInformation {

    long packageSize 0;
    AppDetails cAppDetails;
    public ArrayList<AppDetails.PackageInfoStruct> res;
    Context context;

    public StorageInformation(Context context){
        this.context=context;
    }

    public void getpackageSize() {
        cAppDetails new AppDetails((Activity) context);
        res cAppDetails.getPackages();
        if (res == null)
            return;
        for (int m = 0; m < res.size(); m++) {
            // Create object to access Package Manager
            PackageManager pm = context.getPackageManager();
            Method getPackageSizeInfo;
            try {
                getPackageSizeInfo = pm.getClass().getMethod(
                        "getPackageSizeInfo", String.class,
                        IPackageStatsObserver.class);
                getPackageSizeInfo.invoke(pm, res.get(m).pname,
                        new cachePackState()); //Call the inner class
            catch (SecurityException e) {
                e.printStackTrace();
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        }
    }
/*
* Inner class which will get the data size for application
* */
    private class cachePackState extends IPackageStatsObserver.Stub {
        @Override
        public void onGetStatsCompleted(PackageStats pStats, boolean succeeded)
                throws RemoteException {
            Log.w("Package Name", pStats.packageName "");
            Log.i("Cache Size", pStats.cacheSize "");
            Log.v("Data Size", pStats.dataSize "");
            packageSize = pStats.dataSize + pStats.cacheSize;
            Log.v("Total Cache Size"" " packageSize);
            Log.v("APK Size",pStats.codeSize+"");
        }
    }
}

Here I’m only logging the output data. You can display in list view with custom adapter.

Note: It may not work if in future the method name change or any thing changed in 
IPackageStatsObserver.Stub.

4. Use getPackageSizeInfo method to get data.

I have just called the getPackageSize method from MainActivity class. You can call call this method according to your project. 
MainActivity.java

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //Get the information of all the installed application data                 StorageInformation storageInformation = 
                                new  StorageInformation(MainActivity.this);
          storageInformation.getpackageSize();
   }
}

Run the application. The output can be seen in log. Here is the snap of AndroidMonitor with all data size logged. All the data unit is in byte. Please convert in to KB or MB according to your requirement. 


Please feel free to comment for any clarification or suggestion.















***