通知到达时不会出现抬头通知

时间:2017-06-23 06:54:40

标签: android firebase android-notifications

我正在尝试显示Android应用的通知。通知显示在通知区域中,但即使将优先级设置为“max”,heads up notification也不会出现。 这是我的通知构建器代码

Intent intent = new Intent(this, MainActivity.class);
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
    Log.e("notification arrived","");

    long[] pattern = {500,500,500,500,500};
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Notification.Builder n  = new Notification.Builder(this)
            .setContentTitle("Best Deals")
            .setContentText(body)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentIntent(pIntent)
            .setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_ALL)
            .setPriority(Notification.PRIORITY_MAX)
            .setSound(alarmSound)
            .setVibrate(pattern);

    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(0, n.build());

1 个答案:

答案 0 :(得分:1)

我已经测试了你的代码,一切都按预期运行。

enter image description here

也许你必须改变你的测试环境?

我使用了带有API 25的Nexus 7仿真器。 这些都在我的build.gradle

buildToolsVersion "25.0.2"
minSdkVersion 21
targetSdkVersion 23
  

注意:某些设备/制造商会为您提供禁用(或默认情况下已禁用)抬头通知的选项。