1. Ensure the you have set LaunchMode.SingleTop on your MainActivity:

LaunchMode.SingleTop

     [Activity(Label = "云销管家",
Icon = "@mipmap/ic_launcher",
Theme = "@style/MainTheme",
LaunchMode = LaunchMode.SingleTop,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity, IBDLocationListener
{

In your MainActivity (the FormsAppCompatActivity subclass) add a OnNewIntent override:

OnNewIntent:

 protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
NotificationClickedOn(intent);
}

Now you can check the intent.Action / intent.HasExtra to determine if it is your notification that was send and thus process it. With Xamarin.Forms the easiest would be to use MessagingCenter to send a message that is subscribed to within your .NetStd/PCL Xamarin.Forms code base.

NotificationClickedOn:

         void NotificationClickedOn(Intent intent)
{ if (intent.Action == "LocalNotifierIntent1300" && intent.HasExtra("LocalNotification"))
{
var notificationMessage = intent.Extras.GetString("LocalNotification");
var winnerToast = Toast.MakeText(this, $"{notificationMessage}.", ToastLength.Long);
winnerToast.SetGravity(Android.Views.GravityFlags.Center, , );
winnerToast.Show();
}
}

Send notification example:

 void SendNotifacation()
{
var title = "Winner, Winner, Chicken Dinner";
var message = "You just won a million StackOverflow reputation points"; var intent = new Intent(BaseContext, typeof(MainActivity));
intent.SetAction("ASushiNotification");
intent.PutExtra("MessageFromSushiHangover", message);
var pending = PendingIntent.GetActivity(BaseContext, , intent, PendingIntentFlags.CancelCurrent); using (var notificationManager = NotificationManager.FromContext(BaseContext))
{
Notification notification;
if (Android.OS.Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.O)
{
#pragma warning disable CS0618 // Type or member is obsolete
notification = new Notification.Builder(BaseContext)
.SetContentTitle(title)
.SetContentText(message)
.SetAutoCancel(true)
.SetSmallIcon(Resource.Drawable.icon)
.SetDefaults(NotificationDefaults.All)
.SetContentIntent(pending)
.Build();
#pragma warning restore CS0618 // Type or member is obsolete
}
else
{
var myUrgentChannel = BaseContext.PackageName;
const string channelName = "Messages from SushiHangover"; NotificationChannel channel;
channel = notificationManager.GetNotificationChannel(myUrgentChannel);
if (channel == null)
{
channel = new NotificationChannel(myUrgentChannel, channelName, NotificationImportance.High);
channel.EnableVibration(true);
channel.EnableLights(true);
channel.SetSound(
RingtoneManager.GetDefaultUri(RingtoneType.Notification),
new AudioAttributes.Builder().SetUsage(AudioUsageKind.Notification).Build()
);
channel.LockscreenVisibility = NotificationVisibility.Public;
notificationManager.CreateNotificationChannel(channel);
}
channel?.Dispose(); notification = new Notification.Builder(BaseContext)
.SetChannelId(myUrgentChannel)
.SetContentTitle(title)
.SetContentText(message)
.SetAutoCancel(true)
.SetSmallIcon(Resource.Drawable.icon)
.SetContentIntent(pending)
.Build();
}
notificationManager.Notify(, notification);
notification.Dispose();
}
}

Xamarin Forms 实现发送通知点击跳转的更多相关文章

  1. 向通知栏发送通知点击跳转并传递数据(PendingIntent)传递数据

    // 为发送通知的按钮的点击事件定义事件处理方法 public void send() {///// 第一步:获取NotificationManager NotificationManager nm ...

  2. Xamarin.Forms + Prism,整理页面导航跳转流程

    3个Page,Page1 -> Page2 -> Page3 -> Page2 -> Page1. PageViewModel实现接口:INavigatingAware, IN ...

  3. Xamarin.Forms学习系列之Android集成极光推送

    一般App都会有消息推送的功能,如果是原生安卓或者IOS集成消息推送很容易,各大推送平台都有相关的Sample,但是关于Xamarin.Forms的消息推送集成的资料非常少,下面就说下Xamarin. ...

  4. Xamarin.Forms 简介

    An Introduction to Xamarin.Forms 来源:http://developer.xamarin.com/guides/cross-platform/xamarin-forms ...

  5. 老司机学新平台 - Xamarin Forms开发框架二探 (Prism vs MvvmCross)

    在上一篇Xamarin开发环境及开发框架初探中,曾简单提到MvvmCross这个Xamarin下的开发框架.最近又评估了一些别的,发现老牌Mvvm框架Prism现在也支持Xamarin Forms了, ...

  6. Xamarin.Forms入门学习路线

    Xamarin 介绍 Xamarin是一套跨平台解决方案,目的是使用C#语言创造原生的iOS,Android,Mac和Windows应用. Xamarin的三个优势: Xamarin App拥有原生A ...

  7. C#使用Xamarin开发可移植移动应用(1.入门与Xamarin.Forms页面),附源码

    前言 什么是Xamarin? Xamarin始创于2011年,旨在使移动开发变得难以置信地迅捷和简单. Xamarin的产品简化了针对多种平台的应用开发,包括iOS.Android.Windows P ...

  8. 张高兴的 Xamarin.Forms 开发笔记:为 Android 与 iOS 引入 UWP 风格的汉堡菜单 ( MasterDetailPage )

    所谓 UWP 样式的汉堡菜单,我曾在"张高兴的 UWP 开发笔记:汉堡菜单进阶"里说过,也就是使用 Segoe MDL2 Assets 字体作为左侧 Icon,并且左侧使用填充颜色 ...

  9. Prism for Xamarin.Forms

    一.使用环境 OS:Win 10 16273 VS:VS2017- 15.3.4 Xamarin:4.6.3.4,nuget:2.4 Android Emulator:Visual Studio fo ...

随机推荐

  1. XML和Json的特点

    Xml特点: 1.有且只有一个根节点: 2.数据传输的载体 3.所有的标签都需要自定义 4.是纯文本文件 Json(JavaScript Object Notation)特点: json分为两种格式: ...

  2. Visual Studio 2019 安装

    目录 写在前面 官网下载 安装 等待安装 启动 写在前面 目前工作的开发环境还是旧版本的Visual Studio 2013版.个人感觉还是有点跟不上时代更新迭代的节奏了.毕竟,技术在进步.如果我们也 ...

  3. python Mock 示例

    在Python3.x中,mock已经被集成到了unittest单元测试框架中,所以,可以直接使用. 可能你和我初次接触这个概念的时候会有这样的疑问:把要测的东西都模拟掉了还测试什么呢? 但在,实际生产 ...

  4. A Deep Dive Into Draggable and DragTarget in Flutter

    https://medium.com/flutter-community/a-deep-dive-into-draggable-and-dragtarget-in-flutter-487919f6f1 ...

  5. sql分页优化

    索引优化 注意查询的数据占总数据达到一定量的时候可能导致索引失效.可以用limit或者指定列缩小数据区域可以解决. 以时间orderby排序的limit分页优化 前提用order by分页 limit ...

  6. 十二、vue中watch原理

    1.普通的watch 2.对象属性的watch:   对象和数组都是引用类型,引用类型变量存的是地址,地址没有变,所以不会触发watch.这时我们需要进行深度监听,就需要加上一个属性 deep,值为 ...

  7. Java框架之MyBatis框架(二)

    Mybatis框架是相对于优化dao层的框架,其有效的减少了频繁的连接数据库(在配置文件xml中进行配置),将sql语句与java代码进行分离(写在XXXXmapper.xml文件中,一个表对应一个x ...

  8. SAP错误消息调试之七种武器:让所有的错误消息都能被定位

    目录 长生剑 - SAPGUI Where Used List 碧玉刀 - ABAP调试器观察点 霸王枪 - ABAP调试器动态断点 多情环 - ABAP代码静态扫描 孔雀翎 - SAT 离别钩 - ...

  9. Hybris产品主数据的价格折扣维护

    登录Hybris backoffice的产品管理界面,进入price标签页,点击Create new Discount Row按钮: 在Discount下拉地段里选择10%的折扣,这个产品原来的单价是 ...

  10. HDFS之安全模式

    1.namenode启动的时候,首先将映像文件[fsimage]载入内存,并执行编辑日志[edits]中的各项操作. 2.一旦在内存中成功建立文件系统元数据的映射,则创建一个新的fsimage文件[这 ...