1

I'm using some different kinds of data in my application and I've categorized them by package name like (movies,animations,...). is there is any way to access fragment's package name?!

i tried fragment.getActivity().getPackageName() but it returns Activity's package name

Ebrahim Karimi
  • 732
  • 8
  • 24

2 Answers2

1

This will print the full name of the class with package

fragment.getClass().getPackage().getName()
Ebrahim Karimi
  • 732
  • 8
  • 24
vikas kumar
  • 10,447
  • 2
  • 46
  • 52
0

You can use this, this will return Fragment name along with package name

this.getClass().getName();

You can replace your fragment class name and get only package name, your final method should look like this.

private String getPackageName() {
    return this.getClass().getName().replace("."+this.getClass().getSimpleName(),"");
}
Akhil
  • 6,667
  • 4
  • 31
  • 61