通知到达时不会显示抬头通知

通知到达时不会显示抬头通知

问题描述:

我正在尝试显示Android应用的通知。通知在通知区域中完美显示,但即​​使将优先级设置为“最大”后也不会显示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()); 

代码我测试你的代码,一切按预期工作对我来说。

enter image description here

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

我用过的Nexus 7仿真器API 25 这些都是我build.gradle内:

buildToolsVersion "25.0.2" 
minSdkVersion 21 
targetSdkVersion 23 

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