Sunday, July 12, 2020

How to get All Apps List Installed in Phone

How to get All Apps Icon, Package Name, App Name and Size.


In our Android phone there are 2 types of Apps

1 : System Apps : These are preinstalled Apps and can not be unInstalled without root access.
2 : User apps : These are 3rd party apps that we download from App Stores like Google Play Store.

In the Blog we will discuss how to get all Installed App and their Icon, Package Name, App Name and Size


Method to Fetch All Installed Apps

private void getInstalledApps() {
    PackageManager pm = getPackageManager();

         packs = getPackageManager().getInstalledPackages(0);
  
    for (int i = 0; i < packs.size(); i++) {
        PackageInfo p = packs.get(i);
        
            String appName = p.applicationInfo.loadLabel(getPackageManager()).toString();
            Drawable icon = p.applicationInfo.loadIcon(getPackageManager());
            String packageNAme = p.applicationInfo.packageName;
            File file = new File(p.applicationInfo.publicSourceDir);
            long sizeinBytes = file.length();
            

        
        }
        
    }


How to check whether an App is a System app or User App




boolean isSystemApp(PackageInfo pkgInfo)
{
    if((pkgInfo.applicationInfo.flags & (ApplicationInfo.FLAG_UPDATED_SYSTEM_APP | ApplicationInfo.FLAG_SYSTEM)) > 0)
     {
    
        return true;   // it is System app
    }
    else    {
          return false; // it is user App
     }
}

How to Launch An App

void launchApp(String appPackagneName)
{
    Intent intent1 = getPackageManager().getLaunchIntentForPackage(appPackagneName);
    if(intent1 != null){
        startActivity(intent1);
    }
    else {
        Toast.makeText(this, " Can't launch this.\nThe app may have been UnInstalled or Disabled.", Toast.LENGTH_SHORT).show();
    }
}

How to open App Info in Phone Setting


void showAppInfo(String appPackagneName)
{
    try {
        Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        intent.setData(Uri.parse("package:" +appPackagneName));
        //  Toast.makeText(MainActivity.this, installedApps.get(i).packages, Toast.LENGTH_SHORT).show();      startActivity(intent);
    }
    catch(Exception E){
        Toast.makeText(this, " Can't open App's Info.", Toast.LENGTH_SHORT).show();
    }
}

How to get and Share App's Play Store Link


void shareAppLink(String appPackagneName)
{
  
        String appLink = appItem.name + " Download Link : https://play.google.com/store/apps/details?id=" + appPackageName;
        Intent localIntent = new Intent();

        localIntent.setAction("android.intent.action.SEND");
        localIntent.putExtra("android.intent.extra.TEXT", appLink);
        localIntent.setType("text/plain");
        startActivity(Intent.createChooser(localIntent, "Share App Link"));
    

}

How the open an APP in Google Play Stor


void openAppInPlaystore(String appPackageName )
{
    
     
        try {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
        } catch (android.content.ActivityNotFoundException anfe) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
        }
    
}




I hope you enjoyed it.

No comments:

Post a Comment