Search code examples
androidlauncher

Android Custom Launcher Application


I am working on a custom launcher application. I want to get information like "How many cameras, message or browser applications are installed on my device", that can be default or third party application? Please suggest me if have any idea for this.

Thanks in advance


Solution

  • To get the info you're after, you'll need to use PackageManager class and whatever else it provides. For example, the following code retrieves the list of available "applications", that is Activities that are defined with Launch Intent in their respective AndroidManifest files - together with the .app files that contain them, launcher labels and icons, etc.

    PackageManager pm = getPackageManager();
    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    String _label, _class, _src;
    Drawable _icon;
    
    for (ResolveInfo rInfo : pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED)) {
        if (pm.getLaunchIntentForPackage(rInfo.activityInfo.packageName) == null) {
            continue;
        }
        _class = rInfo.activityInfo.packageName;
        _label = rInfo.activityInfo.loadLabel(pm).toString();
        _src = rInfo.activityInfo.applicationInfo.sourceDir;
        _icon = rInfo.activityInfo.loadIcon(pm);
    
        Log.d("PackageList", "label: " + _label + ", package: " + _class + ", sourceDir: " + _src + ", icon: " + (_icon == null ? "blank" : "present"));
    }