Search code examples
androidandroid-fragmentsbitmapicons

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?


Solution

  • Try this instead of getPackageName()

    getActivity().getPackageName()