繁体   English   中英

Android 通知未显示在一台设备中

[英]Android Notifications not showing up in one device

该通知出现在 2 台设备(小米、Vivo)中,均 >26 SDK。 但它没有出现在我的三星设备上,它也是 >26。

这就是我实施通知的方式

private NotificationManager mNotificationManager1;

public void CreateMessage(String name,String message, Context context){
        SharedPreferences prefs = context.getSharedPreferences(Activity.class.getSimpleName(), Context.MODE_PRIVATE);
        int notificationNumber = prefs.getInt("notificationNumber", 0);

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(context, "Finderr_channel_id1");

        mNotificationManager1 =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
        {
            String channelId1 = "Finderr_channel_id1";
            NotificationChannel channel = new NotificationChannel(
                    channelId1,
                    "Finderr Message",
                    NotificationManager.IMPORTANCE_DEFAULT);
            mNotificationManager1.createNotificationChannel(channel);
            mBuilder.setChannelId(channelId1);
        }


        Intent ii = new Intent(context, NotificationHandler.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, ii, 0);

        NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
        bigText.bigText(name + " sent you a message!");
        bigText.setBigContentTitle(name);
        bigText.setSummaryText(message);

        mBuilder.setContentIntent(pendingIntent);
        mBuilder.setSmallIcon(R.drawable.ic_logo_small);
        mBuilder.setContentTitle(name);
        mBuilder.setContentText(message);
        mBuilder.setPriority(Notification.PRIORITY_MAX);
        mBuilder.setStyle(bigText);

        mNotificationManager1.notify(notificationNumber, mBuilder.build());

        SharedPreferences.Editor editor = prefs.edit();
        notificationNumber++;
        editor.putInt("notificationNumber", notificationNumber);
        editor.commit();
    }

我使用共享首选项来跟踪我的通知计数,以便每条消息都与前一条消息叠加。 虽然,甚至没有显示 1 个通知。

你调用了多少次 CreateMessage 方法? 假设您的应用程序只调用此代码一次:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
        {
            String channelId1 = "Finderr_channel_id1";
            NotificationChannel channel = new NotificationChannel(
                    channelId1,
                    "Finderr Message",
                    NotificationManager.IMPORTANCE_DEFAULT);
            mNotificationManager1.createNotificationChannel(channel);
            mBuilder.setChannelId(channelId1);
        }

我也可以说,当我的应用程序尝试以永久通知启动前台服务时,我在使用三星设备时遇到了一些问题。 详见 dontkillmyapp.com

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM