通知振动不工作

问题描述:

我想设置振动火力通知 但我觉得我不是这样做是正确通知振动不工作

这里是一个代码,

public void onMessageReceived(RemoteMessage remoteMessage) { 
     Intent intent = new Intent(this, MainActivity.class); 
     intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); 
     NotificationCompat.Builder notification = new NotificationCompat.Builder(this); 
     notification.setContentTitle("NEW NOTIFICATION"); 
     notification.setContentText(remoteMessage.getNotification().getBody()); 
     notification.setAutoCancel(true); 
     Bitmap icon = BitmapFactory.decodeResource(getApplicationContext().getResources(),R.drawable.icon); 
     notification.setSmallIcon(R.mipmap.ic_launcher); 
     notification.setLargeIcon(icon); 
     notification.setContentIntent(pendingIntent); 
     NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     manager.notify(0, notification.build()); 
     notification.setVibrate(new long[] { 1000, 1000}); 


    } 
+0

我认为您需要在Firebase控制台中启用振动。检查[this](http://stackoverflow.com/questions/38446300/firebase-cloud-messaging-notification-vibration) –

您需要配置Notification致电notify()。致电notify()后致电setVibrate()。将您的setVibrate()呼叫移至notify()呼叫之前。

另请注意,您需要在清单中拥有VIBRATE权限的<uses-permission>元素。

+0

好吧..让我劈 – Nawaz

+0

没有变化 'notification.setVibrate(new long [] {1000, 1000}); NotificationManager manager =(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(0,notification.build());' – Nawaz