2

The app I am developing requires that I get the package name using PackageManager.

enter image description here

I am able to get the App Icon and and App Name but how do I get the packagename in a way similar to what I have below?

    Drawable appIcon = packageManager
            .getApplicationIcon(packageInfo.applicationInfo);


    String appName = packageManager.getApplicationLabel(
            packageInfo.applicationInfo).toString();
Rohit Tigga
  • 2,373
  • 9
  • 43
  • 81

3 Answers3

0

I figured out that it was

    PACKAGE_NAME = packageInfo.packageName;
Rohit Tigga
  • 2,373
  • 9
  • 43
  • 81
0
private ArrayList results = new ArrayList();
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PackageManager pm = this.getPackageManager();

    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);

    List<ResolveInfo> list = pm.queryIntentActivities(intent,
            PackageManager.PERMISSION_GRANTED);
    for (ResolveInfo rInfo : list) {
        results.add(rInfo.activityInfo.applicationInfo.packageName);
        Log.w("Installed Applications", rInfo.activityInfo.applicationInfo
                .loadLabel(pm).toString());
    }

This gives list of all package names installed in your device.

rInfo.activityInfo.applicationInfo.loadLabel(pm)
                .toString();

This gives u the app names.

rInfo.loadIcon(getPackageManager());

And this gives the appicon.

Jossy Paul
  • 1,267
  • 14
  • 26
0
String package_name= getPackageManager().getPackageInfo(getPackageName(), 0).packageName;

Or

String package_name= MyContext.getPackageName();
Ludger
  • 362
  • 3
  • 16