How to get package name from anywhere?
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
.
How to get Package name from activity name
The only reliable way was Vladyslav Matviienko suggestion, which is storing package name along with each activity name in a hashmap to be like .. Thank you all for your help.
android, how to get package name?
The simple, or another way is to pass Context into the helper class constructor:
MyClassConstructor(Context context){
String packageName = context.getPackageName();
}
Get package name and version of Parent Application from it's dependency
Given a Context
, call getPackageName()
on the Context
to find out the package name of the app. Given the Context
and the package name, you can call getPackageManager().getPackageInfo()
on the Context
to get a PackageInfo
object for the app, which contains versionCode
and versionName
.
How can I get package name in android?
Use : getPackageManager().getPackageInfo(getPackageName(), 0).packageName
Or just MyContext.getPackageName()
You can also create a function:
public String getPackageName(Context context) {
return context.getPackageName();
}
get package installer
I found a method for that:
PackageManager.getInstallerPackageName(String packageName);
This returns the package name of the installer application.
Related Topics
Android Create Shortcuts on the Home Screen
How to Get Pixel Color in Android
Android Drawing Separator/Divider Line in Layout
Separate Back Stack For Each Tab in Android Using Fragments
How to Get the Absolute Coordinates of a View
Self-Signed Ssl Acceptance on Android
How to Disable Bottomnavigationview Shift Mode
How to Make Wrap_Content Work on a Recyclerview
How to Refresh Mediastore on Android
How to Open the "Front Camera" on the Android Platform
How to Hide Navigation Bar Permanently in Android Activity
How to Use Custom Font in a Project Written in Android Studio
Remove Fragment Page from Viewpager in Android