简体   繁体   English

Android通知未显示为消息

[英]Android notification is not showing as a message

The notification it self is working good, but not as I want. 它自己的通知工作正常,但不是我想要的。 It vibrates and shows the icon defined but not as a Watsapp Notification and in the setCategory I put CATEGORY_MESSAGE but still, nothing! 它振动并显示已定义的图标,但不显示为Watsapp Notification,并且在setCategory我放置了CATEGORY_MESSAGE但仍然没有任何内容!

on my App class i put : 在我的App类上,我放了:

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
        NotificationChannel channel = new NotificationChannel(CHANNEL_ID,CHANNEL_NAME,NotificationManager.IMPORTANCE_HIGH);
        channel.setDescription(CHANNEL_DESC);
        channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        NotificationManager manager = getSystemService(NotificationManager.class);
        assert manager != null;
        manager.createNotificationChannel(channel);
    }

Fragment : 片段:

private void T(String message){
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext(),CHANNEL_ID)
            .setContentText(message)
            .setContentTitle("Test")
            .setColor(0xff123456)
            .setSmallIcon(R.drawable.com_facebook_button_icon)
            .setCategory(CATEGORY_MESSAGE)
            .setPriority(PRIORITY_HIGH);
    NotificationManagerCompat compat = NotificationManagerCompat.from(getApplicationContext());
    compat.notify(1,mBuilder.build());

}

This is How I want it to notify : 这就是我希望它通知的方式:

在此处输入图片说明

This is how is current notifying 这是当前通知的方式

在此处输入图片说明

I'm using the SDK 27 我正在使用SDK 27

After discussing with OP in chat, here's my best explanation about what could have happened: 在与OP聊天讨论之后,这是我对可能发生的事情的最佳解释:

A notification channel can only be created once, after which it becomes immutable to the app. 通知频道只能创建一次,之后该频道对应用程序将变为不变。 It can only be tweaked by the user through the Settings. 用户只能通过“设置”对其进行调整。 If someone follows the examples in the official docs first, they might create the channel with IMPORTANCE_DEFAULT . 如果有人首先遵循官方文档中的示例,则他们可能会使用IMPORTANCE_DEFAULT创建频道。 After this, even if they change the code later, the channel will remain at level 'High: Make Sound' and not be set to 'Urgent: Make Sound and pop on screen' as desired. 此后,即使他们稍后更改了代码,该通道也将保持在“高:发出声音”级别,并且不会根据需要设置为“紧急:发出声音并在屏幕上弹出”。 Docs on importance level 重要性等级文件


The code in the question is perfectly fine, and should create a channel with the 'Urgent' level when installed for the first time. 该问题中的代码非常好,并且在首次安装时应创建一个具有“紧急”级别的频道。 In any case, uninstalling the app manually and then installing it again will recreate the channels, setting the level to whatever is mentioned in the latest code. 无论如何,手动卸载应用程序然后再次安装它将重新创建频道,将级别设置为最新代码中提到的内容。

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

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