0

I set up notifications on my android application, using firebase and an http call. This is the code I wrote:

> public class MyFirebaseMessagingService extends
> FirebaseMessagingService {
>     final static String TAG = "sb.pcg";
> 
>     @Override
>     public void onNewToken(String s) {
>         Log.d(TAG, "Token: " + s);
>     }
> 
>     @Override
>     public void onMessageReceived(RemoteMessage remoteMessage) {
>         Log.d(TAG, "MyFirebaseMessagingService.OnMessageReceived");
>         showNotification(remoteMessage.getData().get("message"), "Centro Giovanile");
>     }
> 
>     public void showNotification(String message, String title) {
>         Intent intent = new Intent(this, MainActivity.class);
>         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
>         PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
> 
>         String s = message;
>         String[] separated = s.split("linea2");
> 
>         RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_layout);
>         remoteViews.setImageViewResource(R.id.imIcon, R.mipmap.ic_launcher);
>         remoteViews.setTextViewText(R.id.edTitolo, title);
>         remoteViews.setTextViewText(R.id.edLinea1, separated[0]);
>         remoteViews.setTextViewText(R.id.edLinea2, separated[1]);
> 
>         NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "1")
>                 .setSmallIcon(R.mipmap.ic_launcher)
>                 .setLargeIcon(BitmapFactory.decodeResource(getResources(),
> R.mipmap.ic_launcher))
>                 .setAutoCancel(true)
>                 .setVibrate(new long[]{1000, 1000, 1000, 1000, 1000})
>                 .setLights(Color.RED, 400, 400)
>                 .setTicker(title)
>                 .setContentIntent(pendingIntent)
>                 .setContent(remoteViews)
>                 .setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.wolf));
> 
>         NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
>         notificationManager.notify(0, builder.build());
>     } }

I use this code in several device but in device with android 8 there is no one notification and the code is the same. I updated the notification.builder that was deprecated, but still I don't receive nothing.

Is there any special permission? Or something missing?

Simone
  • 311
  • 4
  • 16

0 Answers0