How to read Package Name in Application Class ? Is it possible.
I tried as below.
..... this.packagename;
Context context = getApplicationContext();
String packageName = context.getPackageName();
Nothing works
How to read Package Name in Application Class ? Is it possible.
I tried as below.
..... this.packagename;
Context context = getApplicationContext();
String packageName = context.getPackageName();
Nothing works
In Application class Constructor i need to read application package name
Get rid of the Application
constructor. You should not have one, just as you do not put a constructor on an Activity
.
Your entry point in Application
is onCreate()
. After you chain to the superclass in super.onCreate()
, getPackageName()
should work. It definitely will not work before then, such as from the constructor you are erroneously creating.
As Blundell notes, if you using Android Studio or Gradle for Android, you are welcome to use BuildConfig.APPLICATION_ID
from anywhere.
public class myapp implements application{}
public class exeapp implements myapp { }
Assume myapp is a custom application class from another.
By implements of myapp class in new application class is it possible to read package name in onCreate()