Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get package name in android?

Tags:

java

android

I need to write some util class by myself and I need the packagename of android app. While I found the packageManager which only can be used in Activity and so on that has context. I only want to get packagename in my class which will be used in android app. So how can I do this? Thank you!

like image 952
user898366 Avatar asked Aug 17 '11 09:08

user898366


People also ask

How do I find out the name of my package?

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 the package name in Android?

All Android apps have a package name. The package name uniquely identifies the app on the device; it is also unique in the Google Play store.

What is package name in APK?

The APK Package Name is the directory of the app on the Android operating system, as well as the address of the app on the Google Play Store. Therefore, the APK Package Name must be unique (multiple apps with the same APK Package Name cannot be published).

Is application ID and package name same?

Every Android app has a unique application ID that looks like a Java package name, such as com. example. myapplication. This ID uniquely identifies your app in Google Play Store.


1 Answers

Use : getPackageManager().getPackageInfo(getPackageName(), 0).packageName Or just MyContext.getPackageName()

You can also create a function:

public String getPackageName(Context context) {
    return context.getPackageName();
}
like image 97
Guillaume Avatar answered Nov 11 '22 14:11

Guillaume