public override void OnReceive(Context context, Intent intent) { string intentActionPrefix = context.PackageName + ".ACTION_"; if (intent.Action == null || !intent.Action.StartsWith(intentActionPrefix)) { return; } Bundle bundle = intent.GetBundleExtra(NotificationConstants.Notification); if (bundle == null) { return; } NotificationManager notificationManager = (NotificationManager)context.GetSystemService(Context.NotificationService); if (notificationManager == null) { return; } int id = bundle.GetInt(NotificationConstants.Id); if (bundle.GetBoolean(NotificationConstants.AutoCancel, true)) { if (bundle.ContainsKey(NotificationConstants.Tag)) { string tag = bundle.GetString(NotificationConstants.Tag); notificationManager.Cancel(tag, id); } else { notificationManager.Cancel(id); } } if (bundle.GetBoolean(NotificationConstants.InvokeApp, true)) { NotificationController.InvokeApp(context, bundle); } else { string Action = "com.huawei.HMSActionService"; Intent sendIntent = new Intent(Action); sendIntent.SetPackage(context.PackageName); sendIntent.PutExtra(NotificationConstants.Notification, bundle); context.StartService(sendIntent); }; }
public override void OnReceive(Context context, Intent intent) { Bundle bundle = intent.Extras; Log.Info("HmsLocalNotificationScheduledPublisher", bundle.ToJsonObject().ToString()); ISharedPreferences sharedPreferences = context.GetSharedPreferences(CoreConstants.PreferenceName, FileCreationMode.Private); string id = bundle.GetInt(NotificationConstants.Id).ToString(); if (sharedPreferences.GetString(id, null) != null) { ISharedPreferencesEditor editor = sharedPreferences.Edit(); editor.Remove(bundle.GetInt(NotificationConstants.Id).ToString()); editor.Apply(); NotificationController.LocalNotificationNow(context, bundle); } }