android - 如何在android studio中制作抬头通知?

标签 android

当我搜索如何显示单挑时,我找到了一个将优先级设置为高但仍然不显示单挑的解决方案。我有一个通知消息服务。它的功能如下。我在设置中遗漏了什么吗?

标题

我的代码:

private void sendNotification(String body, String title) {

    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    remoteViews = new RemoteViews(getPackageName(), R.layout.custom_notification);

    remoteViews.setTextViewText(R.id.title, "Firebase");
    remoteViews.setTextViewText(R.id.body, body);
    remoteViews.setImageViewResource(R.id.icon, R.mipmap.ic_launcher);

    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
    PendingIntent pendingIntent = PendingIntent.getActivities(this, 0, new Intent[]{intent}, PendingIntent.FLAG_ONE_SHOT);
    Uri notificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setCustomContentView(remoteViews)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
            .setPriority(NotificationCompat.PRIORITY_MAX)
            .setContentTitle("Firebase Cloud Messaging")
            .setContentText(body)
            .setCustomHeadsUpContentView(remoteViews)
            .setAutoCancel(false)
            .setDefaults(Notification.DEFAULT_ALL)
            .setTicker(body)
            .setSound(notificationSound)
            .setFullScreenIntent(pendingIntent, true)
            .setContentIntent(pendingIntent);

    notificationManager.notify(0, notifBuilder.build());
}

最佳答案

尝试在通知生成器中将 .setContentIntent(pendingIntent) 替换为 .setFullScreenIntent(pendingIntent, true)

关于android - 如何在android studio中制作抬头通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46294555/

相关文章:

android - Calabash 步骤检查应用程序是否是第一次运行

android - OAuth 1.0 与 Android 4.x 和抄写员

android - 我的应用程序有效,但日志显示 "No package ID ff found for ID 0xffffffff."

android - 如何在 Fragment 中为微调器设置 ArrayAdapter

java - Android:错误:解析失败:cardview 受影响的模块:app

Android 蓝牙 (BLE) onCharacteristicChanged 上的数据损坏

java - 如何通过 ListView Item 链接到网站

java - 当 layoutManager 的 scrollToPositionWithOffset 时项目的 recyclerView 之间空白

android - 屏幕密度为 440 dpi 的设备与在 Google Play 上发布的应用不兼容

java - 为什么我的 Android 代码中出现空指针错误?