Android通知:为什么我的通知这么小?

huangapple 未分类评论51阅读模式
英文:

Android notifications : why my notification so small?

问题

我按照此处给出的说明创建了一个通知(相同的代码)。

我的问题是,我的通知看起来非常小,就像这样:

Android通知:为什么我的通知这么小?

而不是正常大小,就像这里:

Android通知:为什么我的通知这么小?

你知道如何获得“正常大小”的通知吗?

谢谢!

以下是代码部分:

private void showNotif() {

    createNotificationChannel();

    String title = "嗨,大家好!";
    String txt = "你们好吗?:)";
    
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, AlarmBroadcastReceiver.CHANNEL_ID)
            .setSmallIcon(R.drawable.icon)
            .setContentTitle(title)
            .setContentText(txt)
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(txt))
            .setPriority(NotificationCompat.PRIORITY_HIGH);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

    // notificationId是您必须定义的每个通知的唯一整数
    notificationManager.notify(2, builder.build());
}

private void createNotificationChannel() {
    // 只在API 26+上创建NotificationChannel,因为NotificationChannel类是新的,不在支持库中
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        CharSequence name = "XXXXXX"; // getString(R.string.channel_name);
        String description = "XXXXXXX"; // getString(R.string.channel_description);
        int importance = NotificationManager.IMPORTANCE_DEFAULT;
        NotificationChannel channel = new NotificationChannel(AlarmBroadcastReceiver.CHANNEL_ID, name, importance);
        channel.setDescription(description);
        // 将通知渠道注册到系统;在此之后无法更改重要性或其他通知行为
        NotificationManager notificationManager = getSystemService(NotificationManager.class);
        notificationManager.createNotificationChannel(channel);
    }
}

[1]: https://developer.android.com/training/notify-user/build-notification
[2]: https://i.stack.imgur.com/Xbifj.png
[3]: https://i.stack.imgur.com/Y4wBk.png

请注意,我只翻译了代码部分,如有需要,请随时提问。

英文:

I created a notification following the instructions given here (same code).

My problem is that my notification looks very small like these:

Android通知:为什么我的通知这么小?

and not normal size like here:

Android通知:为什么我的通知这么小?

Do you know how to have 'normal size' notifications ?

Thanks !

Here is the code:

 private void showNotif() {

            createNotificationChannel();

            String title = "Hi guys !";
            String txt = "How are you ? :)";

            NotificationCompat.Builder builder = new NotificationCompat.Builder(this, AlarmBroadcastReceiver.CHANNEL_ID)
                    .setSmallIcon(R.drawable.icon)
                    .setContentTitle(title)
                    .setContentText(txt)
                    .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText(txt))
                    .setPriority(NotificationCompat.PRIORITY_HIGH);


            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

// notificationId is a unique int for each notification that you must define
            notificationManager.notify(2, builder.build());





    }


    private void createNotificationChannel() {
        // Create the NotificationChannel, but only on API 26+ because
        // the NotificationChannel class is new and not in the support library
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            CharSequence name = "XXXXXX"; // getString(R.string.channel_name);
            String description = "XXXXXXX"; // getString(R.string.channel_description);
            int importance = NotificationManager.IMPORTANCE_DEFAULT;
            NotificationChannel channel = new NotificationChannel(AlarmBroadcastReceiver.CHANNEL_ID, name, importance);
            channel.setDescription(description);
            // Register the channel with the system; you can't change the importance
            // or other notification behaviors after this
            NotificationManager notificationManager = getSystemService(NotificationManager.class);
            notificationManager.createNotificationChannel(channel);
        }
    }

huangapple
  • 本文由 发表于 2020年6月5日 20:34:14
  • 转载请务必保留本文链接:https://java.coder-hub.com/62215482.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定