为什么要用特殊的字母ü 在android的通知中不显示吗?

cbwuti44  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(273)

我试图显示一个通知,但当消息包含如下字母时ü, 它显示为空白。我读过关于这个主题的不同主题,也许是关于编码的,但我不确定。
我发了信息“测试-üöä" 结果显示在下面。
结果如下:

这是我的onmessagereceivedmethod

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    data = remoteMessage.getData();

    String mandatorId = data.get(MANDATOR_ID);
    String message = data.get(MESSAGE);
    String serialNumber = data.get(PM_ID);

    if (message != null) {
        Log.i("OnMessageReceived: ", message);
        if (isForeground(this, PACKAGE_NAME)) {
            sendDialogNotification(mandatorId, message, serialNumber);
        } else {
            sendNotification(mandatorId, message, serialNumber);
        }
    } else {
        Log.e("OnMessageReceived", "null error");
    }
}

以及sendNotification方法

private void sendNotification(String mandatorId, String message, String serialNumber) {
    String notificationTitle = this.getString(R.string.app_name);

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && notificationManager != null) {
        NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "Default Notifications", NotificationManager.IMPORTANCE_HIGH);
        notificationChannel.setDescription("Status Change Notification");
        notificationChannel.enableLights(true);
        notificationChannel.setLightColor(Color.RED);
        notificationChannel.enableVibration(false);

        notificationManager.createNotificationChannel(notificationChannel);
    }

    if (SharedPrefsUtils.getStringValue(this, SharedPrefsUtils.SESSION_COOKIE_DATA_KEY).equals("")) {
        openAppIntent = new Intent(this, LoginActivity.class);
    } else {
        openAppIntent = new Intent(this, MainActivity.class);
    }

    openAppIntent.putExtra(MANDATOR_ID_KEY, mandatorId);
    openAppIntent.putExtra(MACHINE_SERIAL_NUMBER_KEY, serialNumber);
    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(this);
    taskStackBuilder.addNextIntentWithParentStack(openAppIntent);
    PendingIntent resultPendingIntent = taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), NOTIFICATION_CHANNEL_ID)
            .setSmallIcon(R.drawable.ic_cityline)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_cityline))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
            .setContentTitle(notificationTitle)
            .setContentText(message)
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setContentIntent(resultPendingIntent)
            .setAutoCancel(true);

    int notificationId = SharedPrefsUtils.getIntValue(this, SharedPrefsUtils.NOTIFICATION_UNIQUE_ID_KEY);

    if (notificationManager != null) {
        notificationManager.notify(notificationId, notificationBuilder.build());
        notificationId++;
        if (notificationId > 100000)
            notificationId = 0;
        SharedPrefsUtils.setIntValue(this, SharedPrefsUtils.NOTIFICATION_UNIQUE_ID_KEY, notificationId);
    }

}

private void sendDialogNotification(String mandatorId, String message, String serialNumber) {

    Intent serviceIntent = new Intent(this, MainActivity.class);
    serviceIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (mandatorId != null) {
        serviceIntent.putExtra("ID", mandatorId);
    }
    if (message != null) {
        serviceIntent.putExtra("MSG", message);
    }
    if (serialNumber != null) {
        serviceIntent.putExtra("SERIAL", serialNumber);
    } else {
        serviceIntent.putExtra("SERIAL", "customerNotification");
    }
    getApplicationContext().startActivity(serviceIntent);
}

public static boolean isForeground(Context ctx, String myPackage) {
    ActivityManager manager = (ActivityManager) ctx.getSystemService(ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> runningTaskInfo = manager.getRunningTasks(1);
    ComponentName componentInfo = runningTaskInfo.get(0).topActivity;
    return componentInfo.getPackageName().equals(myPackage);
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题