-1

I am trying to get an application ID from an app.

My final goal is getting push messages to it. But I can't figure out why my package name doesn't show up. Does someone have an solution for it? Or an example app where it is working on?

This is my code I used for getting my package name:

@Override
protected void onCreate(Bundle savedInstanceState) {

    ClassA instanceOfClass = new ClassA();
    String packageName = instanceOfClass.getClass().getPackage().getName();
    System.out.println( "Package Name : " + packageName);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


}
Drogon
  • 360
  • 1
  • 4
  • 18

2 Answers2

1

Are you interested in the Java package name or the Android package name? In the general case, they may be different. An Activity has getPackageName() defined in the ancestor class ContextWrapper and documented as: Return the name of this application's package.

18446744073709551615
  • 16,368
  • 4
  • 94
  • 127
0

Use the code without the instance of the class i.e String packageName = getClass().getPackage() .getName().toString(); This 'll return you the current package name.

Sridhar
  • 95
  • 1
  • 8