I am using only one project to port lite and full versions for that I am just updating Manifest file package names.
My project structure is like this
My Ap
The Kotlin solution:
val packageName = this.javaClass.`package`?.name
Might Be helpfull
package org.kodejava.example.lang;
import java.util.Date;
public class ObtainingPackageName {
public static void main(String[] args) {
//
// Create an instance of Date class, and then obtain the class package
// name.
//
Date date = new Date();
Package pack = date.getClass().getPackage();
String packageName = pack.getName();
System.out.println("Package Name = " + packageName);
//
// Create an insatnce of our class and again get its package name
//
ObtainingPackageName o = new ObtainingPackageName();
packageName = o.getClass().getPackage().getName();
System.out.println("Package Name = " + packageName);
}
}
String packageName = this.getClass().getPackage().getName();
will work definitely.
try this,
try {
Class c = Class.forName("package_name.MyClass");
Object o = c.newInstance();
Package p = o.getClass().getPackage();
System.out.println("Package Name :: " + p.getName());
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
Simple example of some class NotificationListener
:
Timber.d(NotificationListener.class.getPackage().getName());
Timber.d(NotificationListener.class.getSimpleName());
Timber.d(NotificationListener.class.getName());
Output:
D/PermissionsUtil: com.example.receivers
D/PermissionsUtil: NotificationListener
D/PermissionsUtil: com.example.receivers.NotificationListener