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 workin
getApplicationContext() is a method of ContextWrapper ( super class of Activity).
If you want to use it in your classes you will have to pass a reference of a Context or its subclass and then use it
http://developer.android.com/reference/android/content/ContextWrapper.html#getPackageName()
class MyClass {
Context mContext;
public MyClass(Context ctx) [
this.mContext = ctx;
}
String getPackageName() {
mContext.getPackageName();
}
}