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.
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);
}
}
I changed everything you said, but sending the notification through firebase remains the same. Thank you
– S0nkit3
You can add to your question the update of how your code got with my suggestion?
– Paulo Rodrigues
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
– S0nkit3