using System;
|
using System.Net;
|
using System.Threading.Tasks;
|
using Android;
|
using Android.App;
|
using Android.Content;
|
using Android.Net;
|
using Android.Net.Wifi;
|
using Android.OS;
|
using Android.Runtime;
|
using Android.Widget;
|
using CN.Jpush.Android.Api;
|
using HDL_ON;
|
using Java.Util;
|
using Microsoft.AppCenter;
|
using Microsoft.AppCenter.Analytics;
|
using Microsoft.AppCenter.Crashes;
|
using Shared;
|
|
namespace HDL_ON_Android
|
{
|
/// <summary>
|
/// 设定为默认启动的Application
|
/// </summary>
|
[Android.App.Application(Theme = "@style/MyTheme")]
|
public class Application : Android.App.Application, Android.App.Application.IActivityLifecycleCallbacks
|
{
|
//处理安卓接收不到udp命令问题
|
WifiManager.MulticastLock multicast;
|
|
static void reStartApp(Android.App.Application application)
|
{
|
var intent = new Intent(application, typeof(BaseActivity));
|
intent.AddFlags(ActivityFlags.NewTask);
|
application.StartActivity(intent);
|
Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
|
}
|
|
public Application(IntPtr handle, Android.Runtime.JniHandleOwnership ownerShip) : base(handle, ownerShip) { }
|
public override void OnCreate()
|
{
|
|
if (Shared.Application.Activity != null)
|
{
|
//reStartApp(this);
|
return;
|
}
|
|
base.OnCreate();
|
|
WifiManager manager = (WifiManager)this.GetSystemService(Context.WifiService);
|
|
multicast = manager.CreateMulticastLock("UDPwifi");
|
|
|
Language.CurrentLanguage = "Chinese";
|
Locale locale1 = Locale.Default;
|
var localeList = Resources.Configuration.Locale;
|
Console.WriteLine("当前语言:" + localeList.Language);
|
if (localeList.Language == "zh")
|
{
|
Language.CurrentLanguage = "Chinese";
|
}
|
else
|
{
|
Language.CurrentLanguage = "English";
|
}
|
|
RegisterActivityLifecycleCallbacks(this);
|
}
|
|
public void OnActivityCreated(Activity activity, Bundle savedInstanceState)
|
{
|
|
}
|
|
public void OnActivityDestroyed(Activity activity)
|
{
|
//throw new NotImplementedException ();
|
}
|
|
public void OnActivityPaused(Activity activity)
|
{
|
//throw new NotImplementedException ();
|
}
|
|
public void OnActivityResumed(Activity activity)
|
{
|
//throw new NotImplementedException ();
|
}
|
|
public void OnActivitySaveInstanceState(Activity activity, Bundle outState)
|
{
|
//throw new NotImplementedException ();
|
}
|
|
public void OnActivityStarted(Activity activity)
|
{
|
//throw new NotImplementedException ();
|
if (HDL_ON.OnAppConfig.Instance.FirstRunApp)
|
{
|
return;
|
}
|
mCount++;
|
if (mCount == 1)
|
{
|
Console.WriteLine("HHH OnActivityStarted:foreground");
|
BusSocketStart();
|
multicast.Acquire();
|
|
//后台回到前台
|
new HDL_ON.UI.AppUnlockPage().LoadPage();
|
}
|
|
}
|
|
public void OnActivityStopped(Activity activity)
|
{
|
|
mCount--;
|
if (mCount == 0)
|
{
|
Console.WriteLine("HHH OnActivityStopped: background");
|
BusSocketStop();
|
multicast.Release();
|
//进入后台
|
UserInfo.Current.unlockTime = DateTime.Now;
|
|
}
|
}
|
|
|
public override void OnTerminate()
|
{
|
base.OnTerminate();
|
UnregisterActivityLifecycleCallbacks(this);
|
}
|
|
public int mCount;
|
|
///// <summary>
|
///// 是否进入后台
|
///// </summary>
|
//public bool IsEnterBackground = false;
|
|
/// <summary>
|
/// 进入后台的时间
|
/// </summary>
|
DateTime CloseTime = DateTime.Now;
|
|
/// <summary>
|
/// BusSocketStop
|
/// </summary>
|
void BusSocketStop()
|
{
|
//IsEnterBackground = true;
|
CloseTime = DateTime.Now;
|
MainPage.IsEnterBackground = true;
|
//进入后台mqtt正在连接重置状态
|
HDL_ON.DAL.Mqtt.MqttClient.RemoteMqttIsConnecting = false;
|
HDL_ON.DriverLayer.UdpSocket._BusSocket.Stop();
|
|
}
|
|
/// <summary>
|
/// BusSocketStart
|
/// </summary>
|
void BusSocketStart()
|
{
|
//IsEnterBackground = false;
|
|
if (CloseTime.AddSeconds(10) < DateTime.Now)
|
{
|
//后台超过10s就断开MQTT重连
|
//if (HDL_ON.DriverLayer.Control.Ins.IsRemote)
|
{
|
HDL_ON.DAL.Mqtt.MqttClient.DisConnectRemote("closeTime", false);
|
}
|
}
|
|
MainPage.IsEnterBackground = false;
|
HDL_ON.DriverLayer.UdpSocket._BusSocket.Start();
|
HDL_ON.DriverLayer.Control.Ins.SearchLoaclGateway();
|
}
|
|
protected override void Dispose(bool disposing)
|
{
|
base.Dispose(disposing);
|
}
|
|
/// <summary>
|
/// 查询通知权限,并提示
|
/// </summary>
|
public void QueryNotificationPermission()
|
{
|
|
|
}
|
|
|
|
}
|
|
}
|