android - Program do not disturb mode -
when open second activity, turn on not disturb mode on android device. however, want not disturb turn on through second page (either opening or through button created on second page). code found on stack overflow in android manifest file
<uses-permission android:name="android.permission.access_notification_policy" />
i'm not sure go here, appreciated.
use method:
private void setringermode(context context, int mode) { notificationmanager nm = (notificationmanager) context.getsystemservice(context.notification_service); // check dnd permissions api 24+ if (android.os.build.version.sdk_int < 24 || (android.os.build.version.sdk_int >= 24 && !nm.isnotificationpolicyaccessgranted())) { audiomanager audiomanager = (audiomanager) context.getsystemservice(context.audio_service); audiomanager.setringermode(mode); } }
where mode
parameter can audiomanager.ringer_mode_silent or audiomanager.ringer_mode_normal
Comments
Post a Comment