Réponses:
Vous voulez probablement dire Notification.Builder.setLargeIcon(Bitmap), non? :)
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.large_icon);
notBuilder.setLargeIcon(largeIcon);
C'est une excellente méthode pour convertir des images de ressources en Android Bitmap.
... E/CommitToConfigurationOperation: Malformed snapshot token (size): ... E/NotificationService: Not posting notification with icon==0: Notification(pri=0 contentView=null vibrate=null sound=content://settings/system/notification_sound defaults=0x0 flags=0x10 color=0x00000000 vis=PRIVATE) ... E/NotificationService: WARNING: In a future release this will crash the app:...
Drawable myDrawable = getResources().getDrawable(R.drawable.logo);
Bitmap myLogo = ((BitmapDrawable) myDrawable).getBitmap();
Étant donné que l'API 22 getResources().getDrawable()est obsolète, nous pouvons donc utiliser la solution suivante.
Drawable vectorDrawable = VectorDrawableCompat.create(getResources(), R.drawable.logo, getContext().getTheme());
Bitmap myLogo = ((BitmapDrawable) vectorDrawable).getBitmap();
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.my_drawable);
Contextpeut être votre courant Activity.
Voici une autre façon de convertir une ressource Drawable en Bitmap dans Android:
Drawable drawable = getResources().getDrawable(R.drawable.input);
Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
Créer d'abord une image bitmap
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.image);
définissez maintenant le bitmap dans l'icône de Notification Builder ....
Notification.Builder.setLargeIcon(bmp);
Dans le res/drawabledossier,
1. Créez un nouveau Drawable Resources.
2. Entrez le nom du fichier.
Un nouveau fichier sera créé dans le res/drawabledossier.
Remplacez ce code dans le fichier nouvellement créé et remplacez-le ic_action_backpar votre nom de fichier pouvant être dessiné.
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/ic_action_back"
android:tint="@color/color_primary_text" />
Maintenant, vous pouvez l' utiliser avec l' ID de ressources, R.id.filename.