Xamarin.Android 里面的通知
来源:互联网 发布:bytebuffer byte数组 编辑:程序博客网 时间:2024/05/22 01:50
我们每天都离不开手机App应用,也每天都接受各种消息通知,这几天自己刚好在研究Xamarin.Android 里面的通知,在此做个笔记总结,有什么理解不当之处请大家指正。
(1)首先在界面拖3个Button
(2)在MainActivity里面找到界面的对应Button元素(我设定三个Button的ID分别为(button1,button2,button3)
Button StartButton = FindViewById<Button>(Resource.Id.button1); Button EndButton = FindViewById<Button>(Resource.Id.button2); Button VoiceButton = FindViewById<Button>(Resource.Id.button3);
(3)定义一个NotificationManager类型的变量,我取名为notification
private NotificationManager notification;
(4)获取管理通知类,在Xamarin.Android下的通知需要获取NotificationManager服务,而该服务需要通过GetSystemService获取。
<span style="font-size:18px;">//获得系统管理类</span> notification = (NotificationManager) GetSystemService(NotificationService);
(5)为三个button分别挂载事件
//开始通知 StartButton.Click += delegate { //设置通知的图标以及显示的简介Title Notification notify = new Notification(Resource.Drawable.Icon, "普通通知"); //初始化点击通知后打开的活动,我们点击通知之后都会打开对应的活动,所以我们需要初始化一个延迟意图,以便通知可以打开 PendingIntent pintent = PendingIntent.GetActivity(this, 0, new Intent(this, typeof(MainActivity)), PendingIntentFlags.UpdateCurrent); //设置通知的主体 notify.SetLatestEventInfo(this, "通知李白", "你二级没过", pintent); //发送通知 notification.Notify(0, notify);//0为该通知的ID,方便后面接收该通知 };在取消通知里面,notification里面的Cancel方法里面的参数是通知ID,是根据ID来区分究竟应该取消哪一个通知,或者你也可以选择All,进而选择取消全部通知
//取消通知 EndButton.Click += delegate { //根据ID取消通知 notification.Cancel(0); notification.Cancel(1); };
//带有震动,声音的通知 VoiceButton.Click += delegate { Notification notify = new Notification(Resource.Drawable.Icon, "带有声音、LED光和震动的通知"); //设置该通知具有声音、LED光和震动,即所有 notify.Defaults = NotificationDefaults.All; //获取系统默认的通知声音 Android.Net.Uri ringUri = RingtoneManager.GetDefaultUri(RingtoneType.Notification); //设置通知的声音 notify.Sound = ringUri; //设置一秒的震动 notify.Vibrate = new long[] { 1000 }; //设置LED的颜色为绿色 notify.LedARGB = Color.Green; //设置LED显示时间为1s notify.LedOnMS = 1000; //设置LED熄灭时间为1s notify.LedOffMS = 1000; //设置标志位,否则无法显示LED notify.Flags = NotificationFlags.ShowLights | notify.Flags; PendingIntent pintent = PendingIntent.GetActivity(this, 0, new Intent(this, typeof(MainActivity)), 0); notify.SetLatestEventInfo(this, "通知璐璐", "回来吃饺子", pintent); notification.Notify(1, notify); };最后打开Genymotion模拟器,运行一下
好了,大功告成!继续,革命尚未成功,“通知”仍需努力。
0 0
- Xamarin.Android 里面的通知
- Xamarin.Android 照相机的使用
- xamarin android menu的用法
- xamarin android viewpager的用法
- xamarin android listview的用法
- Xamarin.Android活动的生命周期
- Xamarin android spinner的使用方法
- 关于怎么用Xamarin来将JS通知转换成手机系统通知的问题
- Xamarin.Android开发及常见问题的解决
- Xamarin Android SDK无法更新的解决办法
- Xamarin如何生成Android项目的APK
- Xamarin如何生成Android项目的APK
- Xamarin android CardView的使用详解
- Xamarin.android 的pagerview滑动指示器
- XAMARIN Android获取WIFIMAC地址的方法
- Xamarin.Android 中 Handler 的使用
- C#的Xamarin开发小米盒子应用并以WCF实现微信通知
- android通知的使用
- SQL Server 2008 R2 企业版/开发版/标准版(中英文下载,带序列号)
- hdu2767Proving Equivalences【STL版SCCTarjan+缩点】(有注释)
- Nova Liberty blueprints
- JavaScript零碎知识点归纳
- CASE WHEN 及 SELECT CASE WHEN的用法
- Xamarin.Android 里面的通知
- Java上的try catch并不影响性能(转)
- 黑马程序员_java多线程的同步和死锁
- Codeforces 496C Removing Columns(暴力)
- malloc的内存分配之 malloc(0)的内存分配情况
- 【知识】java中判断两个字符串是否相等的问题
- 欢迎使用CSDN-markdown编辑器
- Codeforces 496D Tennis Game(高效)
- Android查看apk签名信息方法