Уведомление Android 8 не отображается - PullRequest
0 голосов
/ 22 октября 2018

Я настроил уведомления на своем андроид-приложении, используя firebase и http-вызов.Это код, который я написал:

> 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());
>     } }

Я использую этот код в нескольких устройствах, но в устройстве с Android 8 нет ни одного уведомления, и код тот же.Я обновил уведомление.стройщик, который устарел, но все равно ничего не получаю.

Есть ли какое-либо специальное разрешение?Или чего-то не хватает?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...