Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get application name from package name

Tags:

android

I want to get the application name from application package name. Somebody please show me how I can get this.

public class AppInstalledListener extends BroadcastReceiver{      @Override     public void onReceive(Context context, Intent intent) {         // TODO Auto-generated method stub         String action = intent.getAction();         if(action.equals("android.intent.action.PACKAGE_ADDED")){             Logger.debug("DATA:"+intent.getData().toString());         }         if(action.equals("android.intent.action.PACKAGE_REMOVED")){             Logger.debug("DATA:"+intent.getData().toString());         }         if(action.equals("android.intent.action.PACKAGE_REPLACED")){             Logger.debug("DATA:"+intent.getData().toString());         }     } } 
like image 938
stuti Avatar asked Apr 30 '11 10:04

stuti


People also ask

How do I find out what app is using a package name?

You can find an app's package name in the URL of your app's Google Play Store listing. For example, the URL of an app page is play.google.com/store/apps/details? id=com.

How do I find my Google apps package name?

One method to look up an app's package name is to find the app in the Google Play app store using a web browser. The package name will be listed at the end of the URL after the '? id='. In the example below, the package name is 'com.google.android.gm'.

What is APK package name?

The Android Package with the file extension apk is the file format used by the Android operating system, and a number of other Android-based operating systems for distribution and installation of mobile apps, mobile games and middleware. It can be written in either Java or Kotlin. APK.


2 Answers

You can use PackageManager class to obtain ApplicationInfo:

final PackageManager pm = getApplicationContext().getPackageManager(); ApplicationInfo ai; try {     ai = pm.getApplicationInfo( this.getPackageName(), 0); } catch (final NameNotFoundException e) {     ai = null; } final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : "(unknown)"); 

This would return the application name as defined in <application> tag of its manifest.

like image 96
Xion Avatar answered Oct 03 '22 15:10

Xion


Try this

final String packageName = "my.application.package" PackageManager packageManager= getApplicationContext().getPackageManager(); String appName = (String) packageManager.getApplicationLabel(packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)); 

and replace packageName with your package full name.

you can get packageName using mContext.getPackageName() where mContext = yourActivityName.this for Activity and getActivity() for fragment.

like image 36
Zar E Ahmer Avatar answered Oct 03 '22 15:10

Zar E Ahmer