2017-06-23 139 views
2

我正在嘗試顯示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()); 

回答

1

代碼我測試你的代碼,一切按預期工作對我來說。

enter image description here

也許你必須改變你的測試環境?

我用過的Nexus 7仿真器API 25 這些都是我build.gradle內:

buildToolsVersion "25.0.2" 
minSdkVersion 21 
targetSdkVersion 23 

注:某些設備/製造商爲您提供了禁用選項(或已禁用它默認情況下)擡頭通知。