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()); } } }
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.
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'.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With