/// <summary> /// 创建 /// </summary> /// <param name="n"></param> /// <param name="packageName"></param> /// <returns></returns> internal static Notification Create(Android.App.Notification n, string packageName) { var notification = new Notification(packageName); Clone(n, notification); return(notification); }
/// <summary> /// 克隆 /// </summary> /// <param name="from"></param> /// <param name="to"></param> private static void Clone(Android.App.Notification from, Android.App.Notification to) { to.When = from.When; to.Icon = from.Icon; to.IconLevel = from.IconLevel; to.Number = from.Number; to.ContentIntent = from.ContentIntent; to.DeleteIntent = from.DeleteIntent; to.FullScreenIntent = from.FullScreenIntent; to.TickerText = from.TickerText; to.TickerView = from.TickerView; to.ContentView = from.ContentView; to.BigContentView = from.BigContentView; if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { to.HeadsUpContentView = from.HeadsUpContentView; to.AudioAttributes = from.AudioAttributes; to.Color = from.Color; to.Visibility = from.Visibility; to.Category = from.Category; to.PublicVersion = from.PublicVersion; } to.LargeIcon = from.LargeIcon; to.Sound = from.Sound; to.AudioStreamType = from.AudioStreamType; to.Vibrate = from.Vibrate; to.LedARGB = from.LedARGB; to.LedOnMS = from.LedOnMS; to.LedOffMS = from.LedOffMS; to.Defaults = from.Defaults; to.Flags = from.Flags; to.Priority = from.Priority; if (Build.VERSION.SdkInt < BuildVersionCodes.Kitkat) { return; } to.Extras = @from.Extras; to.Actions = @from.Actions; }
public override void OnReceive(Context context, Intent intent) { Intent resultIntent; int id = Convert.ToInt32(intent.GetLongExtra("_id", 0)); databasehelper = new Databasehelper(context); Db = databasehelper.WritableDatabase; resultIntent = new Intent(context, typeof(WriteActivity)); resultIntent.PutExtra("_id", id.ToString()); ContentValues cv = new ContentValues(); cv.Put(Databasehelper.COLUMN_NOTIFY, 0); Db.Update(Databasehelper.TEXTTABLE, cv, "_id= ?", new string[] { id.ToString() }); Db.ExecSQL("VACUUM"); Android.App.PendingIntent resultPendingIntent = Android.App.PendingIntent.GetActivity(context, id, resultIntent, Android.App.PendingIntentFlags.UpdateCurrent); NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "ID") .SetSmallIcon(Android.Resource.Drawable.IcButtonSpeakNow) .SetContentTitle("Вам напоминание!") .SetContentText(intent.GetStringExtra("message")) .SetPriority((int)Android.App.NotificationPriority.Default) .SetContentIntent(resultPendingIntent) .SetAutoCancel(true) ; Android.App.NotificationManager manager = (Android.App.NotificationManager)context.GetSystemService(Context.NotificationService); Android.App.Notification notification = builder.Build(); Multitools.createChannelIfNeeded(manager); manager.Notify(id, notification); }