Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: get the application name from inside a module

Tags:

android

module

i'm writing an android module, which i will include in some of my projects. Now i need to get the application name(at runtime), e.g. the name that is set as android:label for the application in the manifest. Obviously i can't use getResources().getString(R.string.app_name) because i can't access the resources of the project that uses this library. Is there another way? I tried getApplicationInfo().name but that is null and i can't find anything else.

like image 734
Ginso Avatar asked Oct 11 '16 13:10

Ginso


People also ask

How do I find the name of an Android app?

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 app name?

As I mentioned, the Play Store also uses the Android app package name to list unique apps. So, the easiest way to find the app package name is via the Play Store.

How do I find my 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 module name in Android Studio?

Module Name: This text is used as the name of the folder where your source code and resources files are visible. Package Name: This is the Java namespace for the code in your module. It is added as the package attribute in the module's Android manifest file.


1 Answers

I tried getApplicationInfo().name but that is null

That is because name comes from the android:name attribute on <application>, and you are not using a custom Application subclass in your app.

i can't find anything else.

Call loadLabel() on the ApplicationInfo, passing in a PackageManager as a parameter, to retrieve the android:label value for an <application> or any component (e.g., <activity>).

like image 186
CommonsWare Avatar answered Oct 05 '22 03:10

CommonsWare