手机锁定/应用程序未打开时,推送通知振动不起作用 [英] Vibration on push-notification not working when phone locked/app not open

查看:44
本文介绍了手机锁定/应用程序未打开时,推送通知振动不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

总是向应用程序发送推送通知,这不是问题.问题是,只有当应用程序打开且手机未锁定时,手机才会在收到来自应用程序的新通知时振动.如果应用未打开或手机被锁定,手机将不会在收到通知时振动.有没有办法让手机在收到通知时振动 即使它被锁定或应用程序没有打开?可能是什么问题?根据我的发现,通知是在以下代码的帮助下创建的:

The push-notifications to the app are always sent, that's not the problem. The problem is that the phone vibrates if it receives a new notifications from the app only if the app is open and the phone is not locked. If either the app is not open or the phone is locked, the phone will not vibrate on received notifications. Would there be a way to make the phone vibrate on received notifications even if it is locked or the app is not open? What could be the problem? From what I found, the notifications are created with the help of the following code:

public class NotifyFirebaseMessagingService extends FirebaseMessagingService {
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        manager.notify(
                remoteMessage.getMessageId(),
                1,
                new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.ic_paperplane)
                        .setContentTitle(remoteMessage.getNotification().getTitle())
                        .setContentText(remoteMessage.getNotification().getBody())
                        .setVibrate(new long[] { 150, 300, 150, 600})
                        .setAutoCancel(true)
                        .build());
        super.onMessageReceived(remoteMessage);
    }
}

清单具有振动和唤醒锁定权限:

The manifest has the vibrate and wake_lock permissions:

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" /

推荐答案

在通知负载中添加:

"notification":{
    "sound":"default"
}

如果不是静音模式会发出声音,当它是振动模式时会振动

This will run sound if it's not silence mode and vibrate when it's vibration mode

这篇关于手机锁定/应用程序未打开时,推送通知振动不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆