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
  • 682
  • 8
  • 21

2 Answers2

1

This will print the full name of the class with package

fragment.getClass().getPackage().getName()
Ebrahim Karimi
  • 682
  • 8
  • 21
vikas kumar
  • 9,263
  • 2
  • 42
  • 47
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,557
  • 3
  • 30
  • 60