In my application I need to know the name of package name. I have no problem when I want to grab it in activities but i can't take it in other classes. Following code is working in activity but i don't know why it has problem in simple class.
String packageName = getPackageName();
In my class I tried to write this code:
Context context = getApplicationContext();
String packageName = context.getPackageName();
but compiler said getApplicationContext()
method is undefined for this class.
How can I take package name within this class?
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='.
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.
Every Android app has a unique application ID that looks like a Java package name, such as com. example. myapp. This ID uniquely identifies your app on the device and in Google Play Store.
The simple, or another way is to pass Context into the helper class constructor:
MyClassConstructor(Context context){
String packageName = context.getPackageName();
}
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