我将Intent添加到Android.Support.V4.App.NotificationCompat.Builder但Extras没有传递到OnNewIntent的重写中,并且似乎该参数始终是相同的Intent 。 这个想法是在用户的通知列表中的foreach通知,我的应用程序创建了一个自定义通知对象,然后创建了Bundle和Intent 。

//custom notification class just contains the information for notifications public class CustomNotification { public string _noteType { get; set; } public string _noteText { get; set; } public string _noteLink { get; set; } public int _noteIndex { get; set; } }

public void SendNotifications(List notificationList)

{

try

{

var _ctx = Android.App.Application.Context;

int _noteCount = 0;

foreach (var note in notificationList)

{

//I'm instantiating a new Intent foreach so not sure why

// each would not have it's own Extras

var resultIntent = new Intent(_ctx, typeof(MainActivity));

var valuesForActivity = new Bundle();

valuesForActivity.PutInt(MainActivity.COUNT_KEY, _count);

//this will always be the same string when it hits OnNewIntent in MainActivity

valuesForActivity.PutString("URL", note._noteLink);

//this will always be the same number when it hits OnNewIntent in MainActivity

valuesForActivity.PutInt("NoteNumber", _noteCount);

resultIntent.PutExtras(valuesForActivity);

var resultPendingIntent = PendingIntent.GetActivity(_ctx, 0, resultIntent, PendingIntentFlags.UpdateCurrent);

resultIntent.AddFlags(ActivityFlags.SingleTop);

// Build the notification:

var builder = new Android.Support.V4.App.NotificationCompat.Builder(_ctx, MainActivity.CHANNEL_ID)

.SetAutoCancel(true) // Dismiss the notification from the notification area when the user clicks on it

.SetContentIntent(resultPendingIntent) // I'm passing the Intent here.. the rest of the builder vars work

.SetContentTitle(note._noteType) // Set the title

.SetNumber(_count) // Display the count in the Content Info

.SetSmallIcon(2130837590) // This is the icon to display

.SetContentText(note._noteText);

MainActivity.NOTIFICATION_ID++;

var notificationManager = Android.Support.V4.App.NotificationManagerCompat.From(_ctx);

notificationManager.Notify(MainActivity.NOTIFICATION_ID, builder.Build());

_noteCount++;

}

}

catch

{

}

}

//this is inside MainActivity.cs

protected override void OnNewIntent(Intent intent)

{

string url = "";

int noteCount = 0;

if (intent != null)

{

//this is always the same url

url = intent.Extras.GetString("URL");

//this is always the same int

noteCount = intent.Extras.GetInt("NoteNumber");

}

try

{

switch (_viewPager.CurrentItem)

{

case 0:

_fm1.LoadCustomUrl(url);

break;

case 1:

_fm2.LoadCustomUrl(url);

break;

case 2:

_fm3.LoadCustomUrl(url);

break;

case 3:

_fm4.LoadCustomUrl(url);

break;

case 4:

_fm5.LoadCustomUrl(url);

break;

}

}

catch

{

}

base.OnNewIntent(intent);

}

我希望当我将Intent传递给构建器时,它将返回唯一值,但是无论我单击哪个通知,相同的字符串始终返回。 在构建每个通知的过程中,我逐步完成了代码,并将唯一的字符串传递到每个Intent 。 我在这里做错了什么?

android 添加意图,c# - Xamarin.Android:如何为每个通知添加唯一的意图 - 堆栈内存溢出...相关推荐

  1. 组件文件已损坏或android内部模块,android - Android Q更新后,模块化系统组件在托管配置文件中不可用 - 堆栈内存溢出...

    在从工作配置文件配置的设备设置应用中将操作系统从Android 9升级到10后,请停止运行. java.lang.RuntimeException: Unable to start activity ...

  2. android消息发送字符串,android - 从Android客户端通过HTTP在HL7消息中发送base64字符串时遇到错误 - 堆栈内存溢出...

    我正在android客户端(API 17)中使用HL7消息,并使用Hapi库生成和解析HL7消息.当我传输小的字符串值时,该消息工作正常. 但是我必须通过Http将图像发送到HL7服务器,为此,我正在 ...

  3. android自动启动无障碍服务,Xamarin.Android:如何开启无障碍服务永久

    我写的辅助服务,以避免USSD请求过程中AlertWindow开幕:Xamarin.Android:如何开启无障碍服务永久 [Service(Label = "BalanceAccessib ...

  4. android framelayout 高度,android - Android:如何将FrameLayout中的线性布局与底部对齐? - 堆栈内存溢出...

    使用属性layout_gravity对齐FrameLayout中的任何视图 android:layout_gravity:"bottom" /> 但是,如果您尝试将其放置在其 ...

  5. android alarm 的权限,android - Android权限被拒绝-com.android.alarm.permission.SET_ALARM - 堆栈内存溢出...

    我正在尝试通过我的应用设置闹钟,但是当我通过执行以下操作启动意图时,如下所述: 如何在Android中使用意图启动闹钟屏幕? public boolean onMenuItemSelected(int ...

  6. android 电视安装apk文件损坏,android - 无法在Android电视盒上安装APK - 堆栈内存溢出...

    我正在为Android TV编写应用程序. 它可以在模拟器上正常运行,并在Android电视盒上以调试模式运行. 但是,当我使用Android Studio生成apk并尝试将该apk安装在同一盒子上时 ...

  7. Android消息向下堆积,android - 从CoordinatorLayout中的按钮单击事件触发NestedScroll折叠动作 - 堆栈内存溢出...

    我有一个CoordinatorLayout,它包含一个ViewPager,该控件使用嵌套的滚动行为可以正常滚动. 但是,我想在单击按钮时触发滚动/折叠行为. 如何通过单击按钮来控制这种崩溃行为. 通过 ...

  8. android studio 抽屉,java - Android导航抽屉(由Android Studio默认提供) - 堆栈内存溢出...

    当我按下导航菜单项的更改时,它的颜色为黄色,直到释放时一直按它为默认.我没有明确编写任何代码来设置这些设置. 我该如何停止?请帮忙. 这是我的代码. 主要布局 xmlns:android=" ...

  9. android 边框重叠,android - Android:recyclerview中的viewitems轮廓与recyclerview边框重叠 - 堆栈内存溢出...

    在我当前的项目中,我有一个RecyclerView ,其边框为圆角矩形. 我在布局xml中使用background view标签对其进行了设置,并产生了正确的效果: ... android:backg ...

  10. android tmp目录权限不够,android - 使用root用户安装APK,处理“ / data / local / tmp /”文件夹的新限制 - 堆栈内存溢出...

    背景 到目前为止,我可以通过以下代码使用root(在应用程序内)安装APK文件: pm install -t -f fullPathToApkFile 并且如果我想(尝试)安装到sd-card: pm ...

最新文章

  1. 自动驾驶十字路口解决方案
  2. vue解决启动报错cjs loader.js Error: Cannot find module ‘../config‘问题
  3. 双摄就能拍银河拍月亮,还有皮卡丘教你手势识别,这是Pixel 4和谷歌的一箩筐新硬件...
  4. 降维(二)----Laplacian Eigenmaps
  5. centos安装Hue 3.7.0
  6. Gulp 前端自动化构建
  7. vue全局注册组件实例
  8. 【剑指offer 07】用迭代和递归两种方法重构二叉树(python实现)
  9. 深入理解 JVM Class文件格式(一)
  10. winfrom 从网页中通过源代码截取文章
  11. ie手机浏览器_Flash之后是不是该IE浏览器了
  12. matlab的czt变换,CZT变换(chirp z-transform)
  13. spring自定义生命周期的几种方法
  14. 存储过程,游标和触发器实例
  15. RT-Thread Nano移植
  16. 洛谷p3803 FFT入门
  17. [it-ebooks]电子书列表
  18. 转 八部众---走出软件作坊:三五个人十来条枪 如何成为开发正规军(二十三)
  19. 项目启动后sqlSessionFactory获取不到创建数据库连接失败
  20. PHP开发环境配置:ThinkPHP与IDE

热门文章

  1. 【回文串问题】分割回文串
  2. 随遇而安也是一种选择
  3. MATLAB实现红眼消除(数字图像处理)
  4. Unity游戏开发前置知识
  5. 孩子像谁软件在线测试,测试你最像哪个动漫人物官方版
  6. GIS功能区类型识别
  7. WinSCP软件安装教程
  8. 计算机组成原理实验:微程序控制实验
  9. Expert C Programming 阅读笔记(CH2)
  10. 当金融科技遇上云原生,蚂蚁金服是怎么做安全架构的?