2017-08-01 36 views
0

通知を受け取ったときにデバイスが振動し続け、ボタンを何回か押すと振動が止まります。Android Studio 'Notification.FLAG_INSISTENT'が動作しない

だから私はこれらの2行を追加します。

Notification notification = notificationBuilder.build(); 

notification.flags |= Notification.FLAG_INSISTENT; 

通知を受け取ったとき、デバイスは1回だけ振動します。

継続的に振動するためには何が必要ですか?

private void showNotification(String title, String message) { 

     Intent intent = new Intent(this, MainActivity.class); 
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); 

     Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 

     NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
       .setSmallIcon(R.mipmap.ic_launcher_plant) 
       .setLights(Color.GREEN,1,1) 
       .setContentTitle(title) 
       .setContentText(message) 
       .setAutoCancel(true) 
       .setContentIntent(pendingIntent) 
       .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) 
       .addAction(R.drawable.ic_menu_camera,"Go CCTV",getNotificationPendingIntent()); 


     NotificationManager notificationManager = 
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

     Notification notification = notificationBuilder.build(); 
     notification.flags |= Notification.FLAG_INSISTENT; 
     notificationManager.notify(0, notificationBuilder.build()); 
    } 

答えて

2

あなたは二回notificationBuilder.build()を呼んでいる:)

代わり

notificationManager.notify(0, notificationBuilder.build());の操作を行います。notificationManager.notify(0, notification);

+0

感謝を!できます!! –

関連する問題