【问题标题】:Android Notification won't vibrate when phone is asleep手机睡眠时Android通知不会振动
【发布时间】:2016-10-19 09:12:00
【问题描述】:

我已经通过堆栈溢出搜索了不同的建议,但到目前为止没有一个对我有帮助。

我正在使用 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());

}

如果有人可以提供一些帮助,那就太好了!

谢谢!

【问题讨论】:

标签: android firebase sleep firebase-cloud-messaging vibration


【解决方案1】:

android中有一个类/方法叫振动器。你可以从这里查看 https://developer.android.com/reference/android/os/Vibrator.html

每当收到通知时,您都可以调用该方法

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-22
    • 2018-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多