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?
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.
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.
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.
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.
For Kotlin
requireActivity().packageName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With