Dim ret As Int=-1
Dim java As JavaObject
java.InitializeContext
Try
ret =java.RunMethod("check_dnd",Null)
Catch
Log(LastException)
End Try
Select ret
Case 0
Log("DnD off")
Case 2
Log("Total Silence")
Case 3
Log("Alarms Only")
Case -1
Log("SettingNotFoundException occured ?")
End Select
Java block
B4X:
#if java
import android.provider.Settings.Global;
import android.provider.Settings.SettingNotFoundException;
public int check_dnd() throws SettingNotFoundException {
return Global.getInt(getContentResolver(), "zen_mode");
}
#end if
Thanks a lot for your lightning fast response. I tried your code and it worked! However, the return code is always 0 or 1 depending on whether DnD is Off/On. This is good enough for me. My android version is 5.1.1, may be on latest version it returns other codes based on "alarm" and "Total Silence" options.
Dim ret As Int=-1
Dim java As JavaObject
java.InitializeContext
Try
ret =java.RunMethod("check_dnd",Null)
Catch
Log(LastException)
End Try
Select ret
Case 0
Log("DnD off")
Case 2
Log("Total Silence")
Case 3
Log("Alarms Only")
Case -1
Log("SettingNotFoundException occured ?")
End Select
Java block
B4X:
#if java
import android.provider.Settings.Global;
import android.provider.Settings.SettingNotFoundException;
public int check_dnd() throws SettingNotFoundException {
return Global.getInt(getContentResolver(), "zen_mode");
}
#end if
I need to add this to a code or class module, seems it only works in a Service or Activity module.
Gives compile time error when adding to code or class module, any idea how to get it working?
Thanks