Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getPackageName() in Fragment

I was using this method to resize markers in a Google Maps activity:

public Bitmap resizeMapIcons(String iconName,int width, int height){
    Bitmap imageBitmap = BitmapFactory.decodeResource(getResources(),getResources().getIdentifier(iconName, "drawable", getPackageName()));
    Bitmap resizedBitmap = Bitmap.createScaledBitmap(imageBitmap, width, height, false);
    return resizedBitmap;
}

Now I wanted to use it in a fragment with MapView, but I get the error "error: cannot find symbol method getPackageName()". What could be the problem?

like image 430
Tamas Koos Avatar asked Feb 13 '17 19:02

Tamas Koos


People also ask

What is the use of getpackagename () method?

The method returns the package name of this entity as a String. Parameter: This method does not accept any paramter. Return Value: This method returns the package name of this entity as a String. Below programs demonstrate the getPackageName () method.

What is context getpackagemanager in Android?

getPackageManager() is a method of Context. You can use this method inside an Activity (because an Activity is a Context), but if you are calling it elsewhere, you need to pass a Context. In a fragment you may also have access to the getActivity() function, which returns the Acitivity-Context.

How to get activity context in fragment?

You can use this method inside an Activity (because an Activity is a Context), but if you are calling it elsewhere, you need to pass a Context. In a fragment you may also have access to the getActivity () function, which returns the Acitivity-Context. Show activity on this post.

How to get the package name of an entity in Java?

The getPackageName () method of java.lang.Class class is used to get the package name of this entity. This entity can be a class, an array, an interface, etc. The method returns the package name of this entity as a String. Parameter: This method does not accept any paramter.


1 Answers

For Kotlin

requireActivity().packageName
like image 104
Ajinkya Kalaskar Avatar answered Sep 29 '22 17:09

Ajinkya Kalaskar