将Xamarin Android中的BroadCast接收中的Chang手机更改为静音模式 [英] Chang Phone to Silent Mode on BroadCast Recieving in Xamarin Android

查看:122
本文介绍了将Xamarin Android中的BroadCast接收中的Chang手机更改为静音模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 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



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();
}
}




我要更改我的电话模式在广播接收时自动在特定时间静音,因此在这里我从时间选择器中选择时间,然后设置Ala ram Manager实例。当待定意图完成时,广播接收器处于活动状态,并且向我显示一条消息,即接收到广播。但是在这里,我想将移动模式更改为无声模式,所以我该怎么做,可以吗?帮我 ?

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.


推荐答案

您可以使用 AudioManager 设置静音 / 振动 / 普通

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以后,除非允许该应用程序被授予请勿打扰访问权限,否则不允许进行会切换请勿打扰的铃声模式调整。

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.

回复:音频管理器

这篇关于将Xamarin Android中的BroadCast接收中的Chang手机更改为静音模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆