2017-06-23 10 views
2

アンドロイドアプリの通知を表示しようとしています。通知は通知領域に完全に表示されますが、優先度を「最大」に設定しても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

たぶん、あなたはあなたのテスト環境を変更することがありますか?

私はこれらが私の build.gradle内にあるAPI 25 でネクサス7エミュレータを使用しました

buildToolsVersion "25.0.2" 
minSdkVersion 21 
targetSdkVersion 23 

注:一部のデバイス/メーカーはあなたに無効にする(または無効になっていするためのオプションを提供しますそれはデフォルトで)ヘッドアップ通知。

関連する問題