首页 > 解决方案 > 如何以编程方式更改通知栏中的应用程序名称

问题描述

我想在通知栏中更改应用程序名称,但找不到简单的解决方案。他们说必须更改应用程序名称。我找到了这个库。

https://github.com/myinnos/AppIconNameChanger

但是太麻烦了。每次更改需要 10 秒。没有机会通过简单的解决方案仅更改通知栏中的应用程序名称吗?

截屏

这是我的通知示例代码

 NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this.getApplicationContext(), "notify_001");
    Intent ii = new Intent(this.getApplicationContext(), MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, ii, 0);

    NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
    bigText.bigText("Big text");
    bigText.setBigContentTitle("Big content title");
    bigText.setSummaryText("summary text");

    mBuilder.setContentIntent(pendingIntent);
    mBuilder.setSmallIcon(R.drawable.ic);
    mBuilder.setContentTitle("Content Title");
    mBuilder.setContentText("Content text");
    mBuilder.setPriority(Notification.PRIORITY_MAX);
    mBuilder.setStyle(bigText);

    NotificationManager mNotificationManager =
            (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);


    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel("notify_001",
                "Channel human readable title",
                NotificationManager.IMPORTANCE_DEFAULT);
        mNotificationManager.createNotificationChannel(channel);
    }

    mNotificationManager.notify(0, mBuilder.build());

标签: androidnotificationsappicon

解决方案


您需要使用 setContentTitle 来更改标题。


推荐阅读