android, how to get package name?

后端 未结 6 2154
长发绾君心
长发绾君心 2021-02-20 02:50

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

6条回答
  •  我在风中等你
    2021-02-20 03:16

    Using instance of the class you can get package name by using getClass().getPackage().getName() to the instance

    Sample Code

    ClassA instanceOfClass = new ClassA();
    String packageName = instanceOfClass.getClass().getPackage().getName();
    System.out.println("Package Name = " + packageName);
    

提交回复
热议问题