首页 > 解决方案 > 我的应用程序以编程方式更改本地语言,但通知以设备语言显示其消息

问题描述

我可以以编程方式更改我的应用程序的语言,但 NotificationCompat 保留设备语言。这是一个本地自我通知(不是来自 Firebase)。

NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
        String id = "id_notif";
        String name = "test_notif";
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel mChannel = notificationManager.getNotificationChannel(id);
            int importance = NotificationManager.IMPORTANCE_HIGH;
            if (mChannel == null) {
                mChannel = new NotificationChannel(id, name, importance);
                mChannel.enableVibration(true);
                mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
                mChannel.enableLights(true);
                mChannel.setShowBadge(true);
                notificationManager.createNotificationChannel(mChannel);
            }
        }



        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, id)
                .setSmallIcon(R.drawable.ic_stat_revue)
                .setColor(getResources().getColor(R.color.colorAccent))
                .setBadgeIconType(BADGE_ICON_SMALL)
                .setContentTitle(this.getResources().getString(R.string.title)).setContentText(this.getResources().getString(R.string.content));
Notification notification = mBuilder.build();
        notificationManager.notify(magazine.getFilePath().hashCode(), notification);

我使用服务类来下载文件,在下载结束时我会显示通知。

class MagazineDownloadService extends WakefulIntentService

有什么问题?

标签: androidpush-notificationlocalizationandroid-notifications

解决方案


推荐阅读