[英]Suppressing vibration in Android Notifications using FCM v1 protocol
我沒有看到我們可以通過 FCMv1 抑制 Android 系統通知振動的方法(即顯示的通知橫幅,包括應用程序未運行時)。 我正在使用python firebase admin sdk 。
在 Android 設備上,我可以選擇在每個應用程序的基礎上抑制通知的聲音,但無法在每個應用程序的基礎上抑制振動。 對我來說唯一的方法是禁用整個系統的振動,這是不可取的。
我試圖通過在我的 FCM 消息中執行此操作來解決
default_vibrate_timings
設置為False
vibrate_timings_millis
設置為[0,0]
希望這不會導致振動。 但是,這不起作用並且通知在目標設備上振動。 有沒有其他辦法? (我不確定 stackoverflow 是否是針對工具集特定問題的最佳論壇,但 Google鼓勵我們在 StackOverflow 上提問)
這就是我所做的。 我實現了一個自定義 FirebaseService:
public class AppFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onNewToken(@NonNull String token) {
super.onNewToken(token);
// do something with your token
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (remoteMessage.getData().size() > 0) {
// do what you want
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
}
}
}
並在清單中添加:
<service
android:name=".AppFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
在這種情況下,發送數據消息允許您保持正常通知的默認行為
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.