modify notification icon

0

Does anyone explain to me why the icon of my notification is small and the notification when it "comes in" does not vibrate or make any sound? Thank you.

importandroid.app.Notification;importandroid.app.NotificationManager;importandroid.app.PendingIntent;importandroid.content.Context;importandroid.content.Intent;importandroid.graphics.BitmapFactory;importandroid.media.RingtoneManager;importandroid.net.Uri;importandroid.support.v4.app.NotificationCompat;importandroid.util.Log;importcom.google.firebase.messaging.RemoteMessage;publicclassMyFirebaseMessagingServiceextendscom.google.firebase.messaging.FirebaseMessagingService{privatestaticfinalStringTAG="MyFirebaseMsgService";

public MyFirebaseMessagingService(){

}

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    String title = remoteMessage.getNotification().getTitle();
    String message = remoteMessage.getNotification().getBody();
    Log.d(TAG, "onMessageReceived: Message Received: \n" +
            "Title: " + title + "\n" +
            "Message: " + message);

    sendNotification(title, message);

}

@Override
public void onDeletedMessages(){

}



private void sendNotification(String title, String messageBody) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);


    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
            .setSmallIcon(R.mipmap.ic_launcher_round)
            .setContentTitle("FCM Message")
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    Notification note = notificationBuilder.build();
    note.defaults = Notification.DEFAULT_VIBRATE;
    note.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    notificationManager.notify(0, note);
}
}
    
asked by anonymous 27.10.2017 / 12:11

1 answer

1

As for the size of the icon, you can add this to your notificationBuilder :

.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))

And to vibrate when the notification arrives, the change looks like this:

Notification note = notificationBuilder.build();
note.defaults = Notification.DEFAULT_VIBRATE;
note.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

notificationManager.notify(0, note);

So you can remove setSound() from above as well.

    
27.10.2017 / 13:16