modify notification icon

Asked

Viewed 640 times

0

Can someone explain to me why my notification icon is small and the notification when it "arrives" does not vibrate or make any sound? Thank you.

inserir a descrição da imagem aqui

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import com.google.firebase.messaging.RemoteMessage;

public class MyFirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {

private static final String TAG = "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);
}
}

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 comes, the change is like this:

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

notificationManager.notify(0, note);

Thus, you can remove the setSound() upstairs as well.

  • I changed everything you said, but sending the notification through firebase remains the same. Thank you

  • You can add to your question the update of how your code got with my suggestion?

  • I’ve already made the code edition, but there will be no need to update something in Firebase for the changes I made to be updated, is that every time I change my code and go to Firebase to test, always appears the same way!? Thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.