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
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…