Android Question Is it possible to disable/enable "do not disturb" mode programmatically ?

palmzac

Active Member
Licensed User
Longtime User
Hi,

Is it possible to disable/enable "do not disturb" mode programmatically ? Thank for you help !
 

Croïd

Active Member
Licensed User
Longtime User
You must call NotificationManager

and

B4X:
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
 
Upvote 0

palmzac

Active Member
Licensed User
Longtime User
Thanks Corid !

Notification Manager ? I don't understand. Would you give me a sample code ?

You must call NotificationManager

and

B4X:
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Requires Android 6+ (API level 23):
B4X:
Sub SetInterruptionFilter (Policy As Int)
   Dim NotificationManager As JavaObject
   NotificationManager = NotificationManager.InitializeContext.RunMethod("getSystemService", Array("notification"))
   If NotificationManager.RunMethod("isNotificationPolicyAccessGranted", Null) = False Then
     Dim in As Intent
     in.Initialize("android.settings.NOTIFICATION_POLICY_ACCESS_SETTINGS", "")
     StartActivity(in)
     Wait For Activity_Resume '<---
     Log("after resume")
   End If
   If NotificationManager.RunMethod("isNotificationPolicyAccessGranted", Null) = True Then
     NotificationManager.RunMethod("setInterruptionFilter", Array(Policy))
   Else
     Log("No permission!")
   End If
End Sub
Manifest editor:
B4X:
AddPermission(android.permission.ACCESS_NOTIFICATION_POLICY)

Policy values: https://developer.android.com/refer...cationManager.html#INTERRUPTION_FILTER_ALARMS
3 = FILTER_NONE
 
Upvote 0
Top