android - 为什么不显示android通知文本?

标签 android

我编写了以下通知代码,我可以看到通知和通知标题,但文本不可见。我用静态值尝试了很多次,但仍然没有得到什么问题。请帮助我,在此先感谢。

private void messagenotification(String msg, String nextid) {


    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    SharedPreferences.Editor editor = settings.edit();
    editor.putString("id", nextid  ).apply();

    Intent intent = new Intent(this, NextActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.blue)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.blue))
            .setContentTitle("Chat")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);



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

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

最佳答案

似乎您在 notificationBuilder 上忘记了 .setContentText("Example")

文档 here

关于android - 为什么不显示android通知文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36739379/

相关文章:

Android 应用因找不到资源而崩溃

java - 如何在 Android 中修复 "The application may be doing too much work on its main thread"?

java - 网页的 HTML 和 Jsoup 响应不一样

java - 在运行时为 Android 执行嵌入在 Java 中的 Groovy 脚本

Android 深色主题只是使颜色变暗,而不是应用夜间主题颜色

java - 解析 JSON 数组时出现异常 "at answer of type org.json.JSONObject cannot be converted to JSONArray"

java - 类转换异常 : MainActivity cannot be cast to Listener

android - 为 Android KitKat 准备 SMS 应用

android - 如何接收出现在 Android 通知栏上的任何通知的事件

遗留 Java Web 应用程序的 Android 开发