Chang Phone to Silent Mode on BroadCast Recieving in Xamarin Android

女生的网名这么多〃 提交于 2019-12-24 18:41:03

问题


MainActivity.cs

 private void StartAlarm() 
{
    Intent myIntent;
    PendingIntent pendingIntent; myIntent = new Intent(this, typeof(AlarmToastReceiver));
    pendingIntent = PendingIntent.GetBroadcast(this, 0, myIntent, 0);
    alarm_manager.Set(AlarmType.RtcWakeup, calndr.TimeInMillis, pendingIntent);
}

AlarmToastReceiver.cs

[BroadcastReceiver(Enabled =true)]
public class AlarmToastReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
    Toast.MakeText(context, "BroadCast Received.", ToastLength.Long).Show();
}
}

I want to Change my Phone mode to Silent at Specific Time automatically on Broadcast receiving, So here i pick the Time from Time-picker, and then set the Ala ram Manager Instance. When the Pending Intent completed , then Broadcast Receiver is active, and a Message is Shown to me,i.e "Broadcast Received.", but here i want to change my Mobile Mode to silent Mode,So how can i do it,can any one help me ? thanks in advance.


回答1:


You can use the AudioManager to set Silent/Vibrate/Normal.

var audioMgr = (AudioManager)GetSystemService(AudioService);
audioMgr.RingerMode = RingerMode.Silent; // In Oreo(+) this will enable DnD mode

From N onward, ringer mode adjustments that would toggle Do Not Disturb are not allowed unless the app has been granted Do Not Disturb Access.

Re: AudioManager



来源:https://stackoverflow.com/questions/47448223/chang-phone-to-silent-mode-on-broadcast-recieving-in-xamarin-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!