private void ShowMessageNotification(string message) { NotificationManagerCompat notificationManager = NotificationManagerCompat.From(MainApplication.GetInstance()); var builder = new NotificationCompat.Builder(MainApplication.GetInstance(), MainApplication.NOTIFICATION_CHANNEL_ID); Intent intent = new Intent(); intent.SetClass(MainApplication.GetInstance(), typeof(MainActivity)); PendingIntent pendingIntent = PendingIntent.GetActivity(MainApplication.GetInstance(), 1, intent, PendingIntentFlags.UpdateCurrent); var currenttimemillis = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds; builder.SetAutoCancel(true); builder.SetContentIntent(pendingIntent); builder.SetWhen(currenttimemillis); builder.SetVisibility(NotificationCompat.VisibilityPublic); builder.SetDefaults(NotificationCompat.DefaultLights); builder.SetContentTitle(MainApplication.NOTIFICATION_CHANNEL_NAME); builder.SetContentText(message); Notification notification = builder.Build(); notificationManager.Notify(0, notification); }
public static string GetApplicationName() { if (sApplicationName == null) { if (!MainApplication.Initialized) { return(""); } var app = MainApplication.GetInstance(); Android.Content.PM.PackageManager pm; Android.Content.PM.ApplicationInfo ai; try { pm = app.PackageManager; ai = pm.GetApplicationInfo(app.PackageName, 0); sApplicationName = pm.GetApplicationLabel(ai).ToString(); } catch (Android.Content.PM.PackageManager.NameNotFoundException e) { e.PrintStackTrace(); sApplicationName = app.PackageName; } } return(sApplicationName); }
/// <summary> /// 判断本机上是否有能处理当前Intent的Activity /// </summary> /// <returns></returns> protected bool DoesActivityExists() { if (!MainApplication.Initialized) { return(false); } var app = MainApplication.GetInstance(); Android.Content.PM.PackageManager pm = app.PackageManager; var list = pm.QueryIntentActivities(intent, Android.Content.PM.PackageInfoFlags.MatchDefaultOnly); return(list != null && list.Count() > 0); }
public override void OnReceive(Context context, Intent intent) { this.context = context; string action = intent.Action; if ("android.intent.action.USER_PRESENT".Equals(action) || "android.intent.action.ACTION_POWER_CONNECTED".Equals(action) || "android.intent.action.ACTION_POWER_DISCONNECTED".Equals(action)) { this.StartPushService(); } ///切换到后台 弹通知栏 if (MainApplication.GetInstance().IsAppInBackground()) { ShowMessageNotification("DCMS正在后台运行...."); } }