Get package names and class names for all applicat

2020-04-11 10:37发布

问题:

Does anyone know the class name and package name for any of these applications:

youtube facebook amazon mp3 google talk camera maps text message dialer/phone launcher android market messaging contacts Social Networking Advanced Task Killer

I'm trying to make buttons to open these applications. Surely there must be an easier way than figuring out the package and class name for every application. If there is let me know how to do it. Thanks! :)

回答1:

class PInfo {
    private String appname = "";
    private String pname = "";
    private String classname = "";
    private int versionCode = 0;
    private Drawable icon;
    private void prettyPrint() {
        Log.d("Applist ",appname + "   " + pname + "   " + classname + "   " + versionCode);

    }
}





public ArrayList<PInfo> getPackages() {
     Log.d("AppNo", "Inside Packages"); 
    ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */
    final int max = apps.size();
    Log.d("AppNo", "no of apps "+max); 
    for (int i=0; i<max; i++) {
        apps.get(i).prettyPrint();

    }
    return apps;
}

public ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
    ArrayList<PInfo> res = new ArrayList<PInfo>();        
    List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
    for(int i=0;i<packs.size();i++) {
        PackageInfo p = packs.get(i);



        if ((!getSysPackages) && (p.versionName == null)) {
            continue ;
        }
        PInfo newInfo = new PInfo();
        newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
        newInfo.pname = p.packageName;
        newInfo.classname = p.applicationInfo.className;
        newInfo.versionCode = p.versionCode;
        newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());

        Intent app=getPackageManager().getLaunchIntentForPackage(p.packageName);


            if(app!=null){
                dleteintent(app,newInfo.appname, newInfo.icon);
                res.add(newInfo);
        }

    }
    return res;

}

Using PakageInfo you can get package name, application Name but not sure about application class name

Using this example you can list all applications install in your device and can get there information.



回答2:

You can look up the package name and many other parts of the AndroidManifest.xml by pulling the development tools from the emulator, and install it on the device with the requested applications. you can execute these commands at the command prompt to do this.

while the emulator is connected, run:

/path-to-android-sdk/platform-tools/adb pull /system/app/DevelopmentTools.apk

disconnect the emulator, connect the device, and run:

/path-to-android-sdk/platform-tools/adb install DevelopmentTools.apk