Answers for "android get package name"

0

android get package name

An idea is to have a static variable in your main activity, instantiated to be the package name. Then just reference that variable.

You will have to initialize it in the main activity's onCreate() method:

Global to the class:

public static String PACKAGE_NAME;
Then..

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    PACKAGE_NAME = getApplicationContext().getPackageName();
}
You can then access it via Main.PACKAGE_NAME.
Posted by: Guest on March-03-2021

Code answers related to "android get package name"

Browse Popular Code Answers by Language