我已经通过堆栈溢出搜索了不同的建议,但到目前为止没有人帮助过我。
我正在使用firebase测试推送通知。我的应用程序中使用的服务很好地检索消息有效负载,并在应用程序或电话打开时构造并显示通知。当我锁定手机时,仍会从firebase检索到该消息并且通知仍在构建中,但问题是,它似乎没有振动我的手机,所以我不知道有任何通知已收到所有
这是我的服务以及构建通知的地方:
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO: Handle FCM messages here.
// If the application is in the foreground handle both data and notification messages here.
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated.
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(remoteMessage.getFrom())
.setContentText(remoteMessage.getNotification().getBody())
.setPriority(Notification.PRIORITY_MAX)
.setVibrate(new long[] {100, 500, 100, 500, 100 ,500});
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(001, notificationBuilder.build());
}
如果有人能提供一些帮助,那就太棒了!
谢谢!
答案 0 :(得分:-1)
android中有一个叫做vibrator的类/方法。你可以从这里查看 https://developer.android.com/reference/android/os/Vibrator.html
每当收到通知时,您都可以调用该方法