簡體   English   中英

android檢查是否以編程方式啟用或禁用“允許聲音”通知設置

[英]android check if "Allow sound" notification setting is enabled or disable programmatically

所以我按照這個鏈接來解決我的問題。 但我認為答案已經過時了。 代碼不起作用。

int importance = manager.getImportance();
boolean soundAllowed = importance < 0 || importance >= NotificationManager.IMPORTANCE_DEFAULT;

所以這是我目前用來檢測通知聲音是打開還是關閉的條件(其中 manager 是 NotificationManager 類的對象) 但它不起作用。

我想檢查通知聲音是打開還是關閉。 如果它關閉,則通知用戶將其打開。

謝謝你的閱讀

在您的以下代碼中,如果用戶沒有為通知指定任何內容,或者他具有更高的通知重要性:到處顯示,發出噪音和偷看。 那么你的 soundAllowed 是真的。 我認為你應該刪除重要性 < 0 這樣你就會得到這個 soundAllowed 變量,只有當用戶對通知聲音給予更高的重要性時才為真

boolean soundAllowed = importance < 0 || importance >= NotificationManager.IMPORTANCE_DEFAULT; // where default value is 3

請檢查此處的值以獲得更清晰的信息。

https://developer.android.com/reference/android/app/NotificationManager#IMPORTANCE_NONE

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM