public MainApplication(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) { Initialized = true; _context = this; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; AndroidEnvironment.UnhandledExceptionRaiser += AndroidEnvironment_UnhandledExceptionRaiser; Connectivity.ConnectivityChanged += Connectivity_ConnectivityChanged; }
/// <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正在后台运行...."); } }
public MainApplication(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) { instance = this; }
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); }