【问题标题】:Notification Code added in Service but not working通知代码添加到服务中但不起作用
【发布时间】:2019-09-04 15:42:51
【问题描述】:

我在我的 android 服务中添加了通知代码。

试过了 Notifications Code in Android

        Log.e("TAG","In 2");
        Intent viewIntent = new Intent(getApplicationContext(), Restarter.class);

        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, viewIntent , PendingIntent.FLAG_UPDATE_CURRENT);
        Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.logo)
                .setContentTitle(getResources().getString(R.string.app_name))
                .setAutoCancel(true)
                .setContentIntent(pendingIntent);


        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
        notificationBuilder.setStyle(inboxStyle);
        inboxStyle.setBigContentTitle("sdjshfjnds");
        inboxStyle.addLine("sdjjsdfn");
        notificationBuilder.setStyle(inboxStyle);

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        int NOTIFICATION_ID = 100;
        notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());

我收到了日志消息,但没有收到通知。

【问题讨论】:

    标签: android push-notification notifications


    【解决方案1】:

    这是旧答案,现在是 2015 年。现在它不是实际的。请查看实际文档:https://developer.android.com/training/notify-user/build-notification

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-30
      • 1970-01-01
      • 2011-11-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多