From 26d1cdf2f5246c1ad7890e6740444c4a6a80e6fb Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期二, 11 八月 2020 13:21:10 +0800
Subject: [PATCH] 合并了新代码

---
 ZigbeeApp/GateWay.Droid/Application.cs |  164 ++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 122 insertions(+), 42 deletions(-)

diff --git a/ZigbeeApp/GateWay.Droid/Application.cs b/ZigbeeApp/GateWay.Droid/Application.cs
index d828f44..46946fd 100755
--- a/ZigbeeApp/GateWay.Droid/Application.cs
+++ b/ZigbeeApp/GateWay.Droid/Application.cs
@@ -26,13 +26,13 @@
     {
         public void OnReq(BaseReq p0)
         {
-
+            
         }
         protected override void OnNewIntent(Intent intent)
         {
             base.OnNewIntent(intent);
             Intent = intent;
-            com.hdl.home.Application.api.HandleIntent(intent, this);
+            com.hdl.home.Application.api?.HandleIntent(intent, this);
             //Finish();
         }
         public static Action<string> RespAction;
@@ -73,32 +73,59 @@
             // 灏嗗簲鐢ㄧ殑appId娉ㄥ唽鍒板井淇�
             //api.RegisterApp("wx2ec8f53f6fa36e82");
 
-          com.hdl.home.Application.api.HandleIntent(Intent, this);
+          com.hdl.home.Application.api?.HandleIntent(Intent, this);
         }
     }
-    /// <summary>鈥�    /// 璁惧畾涓洪粯璁ゅ惎鍔ㄧ殑Application鈥�    /// </summary>鈥�    [Android.App.Application]鈥�    public class Application : Android.App.Application鈥�    {鈥�        public Application(IntPtr handle, Android.Runtime.JniHandleOwnership ownerShip) : base(handle, ownerShip) { }鈥ㄢ��        public override void OnCreate()鈥�        {
-            //瀹夊崜閰嶇綉鍒濆
-            //var result = Com.Mediatek.Elian.ElianNative.LoadLib();
-            //if (!result)
-            //{
-            //    System.Console.WriteLine("Error,can't load elianjni lib");
-            //}
-            initAll();鈥�            base.OnCreate();
+    /// <summary>鈥�    /// 璁惧畾涓洪粯璁ゅ惎鍔ㄧ殑Application鈥�    /// </summary>鈥�    [Android.App.Application()]鈥�    public class Application : Android.App.Application鈥�    {鈥�        public Application(IntPtr handle, Android.Runtime.JniHandleOwnership ownerShip) : base(handle, ownerShip) { }鈥ㄢ��        public override void OnCreate()鈥�        {
+            //濡傛灉涓嶆槸App鐨勪富杩涚▼,鍒欎笉闇�瑕佸鐞�
+            if (this.IsCurrentAppProcess == false)
+            {
+                base.OnCreate();
+                return;
+            }
+            try
+            {
+                //杩欎釜涓滆タ濂藉儚鍙兘浼氬嚭寮傚父
+                this.initAll();
+            }鈥�            catch (Exception ex)鈥�            {
+                //璋冭瘯:璁板綍绯荤粺寮傚父
+                Shared.Phone.UserCenter.HdlLogLogic.Current.WriteOtherText(Shared.Phone.UserCenter.DirNameResourse.SystemLogFile, ex.Message + "\r\n" + ex.StackTrace, true, false);
+            }鈥�            base.OnCreate();
             // 閫氳繃WXAPIFactory宸ュ巶锛岃幏鍙朓WXAPI鐨勫疄渚�
-            api = WXAPIFactory.CreateWXAPI(this, "wx2ec8f53f6fa36e82", true);
+            //api = WXAPIFactory.CreateWXAPI(this, "wx2ec8f53f6fa36e82", true);
 
             // 灏嗗簲鐢ㄧ殑appId娉ㄥ唽鍒板井淇�
-            api.RegisterApp("wx2ec8f53f6fa36e82");
+            api?.RegisterApp("wx2ec8f53f6fa36e82");
+        }
+
+        /// <summary>
+        /// 鍒ゆ柇褰撳墠杩涚▼鏄笉鏄疉pp鑷繁鐨勪富杩涚▼
+        /// </summary>
+        private bool IsCurrentAppProcess
+        {
+            get
+            {
+                var activityManager = (ActivityManager)GetSystemService(ActivityService);
+                var listProcess = activityManager.RunningAppProcesses;
+                foreach (var process in listProcess)
+                {
+                    if (process.ProcessName == "com.evoyo.home" && process.Pid == Android.OS.Process.MyPid())
+                    {
+                        return true;
+                    }
+                }
+                return false;
+            }
         }
 
        internal static IWXAPI api;
 
         public static void WXLogin() {
             var req = new SendAuth.Req { Scope = "snsapi_userinfo", State = "ZigbeeApp" };
-            api.SendReq(req);
+            api?.SendReq(req);
         }
-        /// <summary>鈥�        /// 鎵�鏈夊垵濮嬪寲鍏ㄩ儴鍦ㄨ繖涓柟娉曞疄鐜扳��        /// </summary>鈥�        void initAll()鈥�        {
-            Shared.Application.IsGpsEnable = false;
+        /// <summary>鈥�        /// 鎵�鏈夊垵濮嬪寲鍏ㄩ儴鍦ㄨ繖涓柟娉曞疄鐜扳��        /// </summary>鈥�        void initAll()鈥�        {
+            Shared.Application.IsGpsEnable = System.IO.File.Exists(Shared.Phone.UserCenter.DirNameResourse.OpenGbsFile);
 
             //璁剧疆鏋佸厜璋冭瘯妯″紡锛屼负false鏃跺彧鎵撳嵃璀﹀憡淇℃伅
             // System.Console.WriteLine($"AAA : {System.DateTime.Now.ToString()}");
@@ -159,11 +186,17 @@
                 Shared.Application.FontSize = 12;
                 AppCenter.Start("4802834a-e7e9-4dd8-93f1-c2f88f0bd464", typeof(Analytics), typeof(Crashes));鈥�#if Release鈥�                //淇濆瓨鑾峰彇鐨勬瀬鍏夋湇鍔″櫒涓婄殑娉ㄥ唽ID鍒版湰鍦版枃浠垛��                var registrationId = JPushInterface.GetRegistrationID(activity);
                 System.Console.WriteLine("registrationId-鏋佸厜id=" + registrationId);
-                if (!string.IsNullOrEmpty(registrationId))鈥�                {鈥�                    Shared.Common.Config.Instance.RegistrationID = registrationId;鈥�                    Shared.Common.Config.Instance.Save();鈥�                }鈥�                //璋冭瘯:璁板綍鏋佸厜ID鈥�                Shared.Phone.UserCenter.HdlLogLogic.Current.WriteOtherText(Shared.Phone.UserCenter.DirNameResourse.JiguangFile, "receive1:" + registrationId, true, true);鈥�#endif鈥�            };鈥ㄢ��           鈥�            BaseActivity.RefreshUIAction += (activity) => {鈥�                Shared.Language.CurrentLanguage = "Chinese";鈥�                Shared.Common.CommonPage.Instance.Show();鈥�             };鈥ㄢ��            BaseActivity.NetworkStateChanged += (v) =>鈥�            {鈥�            };鈥�            BaseActivity.OnDestroyAction += (activity) => {鈥�            //socket鍋滄杩炴帴鈥�            //ZigBee.Device.ZbGateway.FindGateWaySocket.Stop();鈥�            };鈥ㄢ��            HDLUtils.SetAuthoritiesName("com.hdl.home.fileProvider");鈥�         }鈥ㄢ��        public static bool IsShowTip = true;鈥�        JpushNotificationReceiver myReceiver = new JpushNotificationReceiver { };鈥ㄢ��        /// <summary>鈥�        /// 椤圭洰鍚姩鏃剁綉缁滄煡璇⑩��        /// </summary>鈥�        void checkSomeInfo()鈥�        {鈥�            var status = isNetworkAvailable(this);鈥�            string internetStatus = "Available";鈥�            if (!status)鈥�            {鈥�                internetStatus = "UnaVailable";鈥�            }鈥�            else鈥�            {鈥�                var isWifi = isWifiConnected(this);鈥�                if (isWifi)鈥�                {鈥�                    internetStatus = "WiFiConnect";鈥�                }鈥�                else鈥�                {鈥�                    internetStatus = "MobileConnect";鈥�                }鈥�            }鈥ㄢ��            int connectState = 0;鈥�            if (internetStatus == "UnaVailable")鈥�            {鈥�                connectState = 0;鈥�            }鈥�            else if (internetStatus == "WiFiConnect")鈥�            {鈥�                connectState = 2;鈥�            }鈥�            else鈥�            {鈥�                connectState = 1;鈥�            }鈥�            //ZigBee.Device.ZbGateway.CheckConnection(connectState);鈥�         }鈥ㄢ��        /// <summary>鈥�        /// 缃戠粶鏄惁鍙敤鈥�        /// </summary>鈥�        /// <returns><c>true</c>, if network available was ised, <c>false</c> otherwise.</returns>鈥�        /// <param name="context">Context.</param>鈥�        bool isNetworkAvailable(Context context)鈥�        {鈥�            var cm = (ConnectivityManager)context.GetSystemService(ConnectivityService);鈥ㄢ��            if (cm == null || cm.ActiveNetworkInfo == null)鈥�            {鈥�                //褰撳墠缃戠粶涓嶅彲鐢ㄢ��                return false;鈥�            }鈥�            else鈥�            {鈥�                return cm.ActiveNetworkInfo.IsAvailable;鈥�            }鈥�        }鈥ㄢ��        /// <summary>鈥�        /// 缃戠粶鏄惁杩炴帴鈥�        /// </summary>鈥�        /// <returns><c>true</c>, if wifi connected was ised, <c>false</c> otherwise.</returns>鈥�        /// <param name="context">Context.</param>鈥�        bool isWifiConnected(Context context)鈥�        {鈥�            if (context != null)鈥�            {鈥�                var cm = (ConnectivityManager)context.GetSystemService(ConnectivityService);鈥ㄢ��                var mWiFiNetworkInfo = cm.GetNetworkInfo(ConnectivityType.Wifi);鈥�                if (Android.Net.NetworkInfo.State.Connected == mWiFiNetworkInfo.GetState())鈥�                {鈥�                    //褰撳墠缃戠粶鏄疻i-Fi杩炴帴鈥�                    return true;鈥�                }鈥ㄢ��                var moWiFiNetworkInfo = cm.GetNetworkInfo(ConnectivityType.Mobile);鈥�                if (Android.Net.NetworkInfo.State.Connected == moWiFiNetworkInfo.GetState())鈥�                {鈥�                    //褰撳墠缃戠粶鏄疢obile杩炴帴鈥�                    return false;鈥�                }鈥�            }鈥�            return false;鈥�        }
+                if (!string.IsNullOrEmpty(registrationId))鈥�                {鈥�                    Shared.Common.Config.Instance.RegistrationID = registrationId;鈥�                    Shared.Common.Config.Instance.Save();鈥�                }鈥�                //璋冭瘯:璁板綍鏋佸厜ID鈥�                Shared.Phone.UserCenter.HdlLogLogic.Current.WriteOtherText(Shared.Phone.UserCenter.DirNameResourse.JiguangFile, "receive1:" + registrationId, true, true);鈥�#endif鈥�            };鈥ㄢ��           鈥�            BaseActivity.RefreshUIAction += (activity) => {鈥�                Shared.Language.CurrentLanguage = "Chinese";鈥�                Shared.Common.CommonPage.Instance.Show();鈥�             };鈥ㄢ��            BaseActivity.NetworkStateChanged += (v) =>鈥�            {鈥�            };鈥�            BaseActivity.OnDestroyAction += (activity) => {鈥�            //socket鍋滄杩炴帴鈥�            //ZigBee.Device.ZbGateway.FindGateWaySocket.Stop();鈥�            };鈥ㄢ��            HDLUtils.SetAuthoritiesName("com.evoyo.home.fileProvider");鈥�         }鈥ㄢ��        public static bool IsShowTip = true;鈥�        JpushNotificationReceiver myReceiver = new JpushNotificationReceiver { };鈥ㄢ��        /// <summary>鈥�        /// 椤圭洰鍚姩鏃剁綉缁滄煡璇⑩��        /// </summary>鈥�        void checkSomeInfo()鈥�        {鈥�            var status = isNetworkAvailable(this);鈥�            string internetStatus = "Available";鈥�            if (!status)鈥�            {鈥�                internetStatus = "UnaVailable";鈥�            }鈥�            else鈥�            {鈥�                var isWifi = isWifiConnected(this);鈥�                if (isWifi)鈥�                {鈥�                    internetStatus = "WiFiConnect";鈥�                }鈥�                else鈥�                {鈥�                    internetStatus = "MobileConnect";鈥�                }鈥�            }鈥ㄢ��            int connectState = 0;鈥�            if (internetStatus == "UnaVailable")鈥�            {鈥�                connectState = 0;鈥�            }鈥�            else if (internetStatus == "WiFiConnect")鈥�            {鈥�                connectState = 2;鈥�            }鈥�            else鈥�            {鈥�                connectState = 1;鈥�            }鈥�            //ZigBee.Device.ZbGateway.CheckConnection(connectState);鈥�         }鈥ㄢ��        /// <summary>鈥�        /// 缃戠粶鏄惁鍙敤鈥�        /// </summary>鈥�        /// <returns><c>true</c>, if network available was ised, <c>false</c> otherwise.</returns>鈥�        /// <param name="context">Context.</param>鈥�        bool isNetworkAvailable(Context context)鈥�        {鈥�            var cm = (ConnectivityManager)context.GetSystemService(ConnectivityService);鈥ㄢ��            if (cm == null || cm.ActiveNetworkInfo == null)鈥�            {鈥�                //褰撳墠缃戠粶涓嶅彲鐢ㄢ��                return false;鈥�            }鈥�            else鈥�            {鈥�                return cm.ActiveNetworkInfo.IsAvailable;鈥�            }鈥�        }鈥ㄢ��        /// <summary>鈥�        /// 缃戠粶鏄惁杩炴帴鈥�        /// </summary>鈥�        /// <returns><c>true</c>, if wifi connected was ised, <c>false</c> otherwise.</returns>鈥�        /// <param name="context">Context.</param>鈥�        bool isWifiConnected(Context context)鈥�        {鈥�            if (context != null)鈥�            {鈥�                var cm = (ConnectivityManager)context.GetSystemService(ConnectivityService);鈥ㄢ��                var mWiFiNetworkInfo = cm.GetNetworkInfo(ConnectivityType.Wifi);鈥�                if (Android.Net.NetworkInfo.State.Connected == mWiFiNetworkInfo.GetState())鈥�                {鈥�                    //褰撳墠缃戠粶鏄疻i-Fi杩炴帴鈥�                    return true;鈥�                }鈥ㄢ��                var moWiFiNetworkInfo = cm.GetNetworkInfo(ConnectivityType.Mobile);鈥�                if (Android.Net.NetworkInfo.State.Connected == moWiFiNetworkInfo.GetState())鈥�                {鈥�                    //褰撳墠缃戠粶鏄疢obile杩炴帴鈥�                    return false;鈥�                }鈥�            }鈥�            return false;鈥�        }
 
        
-    }
-
+    }
+
+    [BroadcastReceiver(Name = "com.evoyo.home.JpushNotificationReceiver", Exported = false, Enabled = true)]
+    [IntentFilter(new string[] { "cn.jpush.android.intent.REGISTRATION",
+               "cn.jpush.android.intent.MESSAGE_RECEIVED",
+                "cn.jpush.android.intent.NOTIFICATION_RECEIVED",
+                "cn.jpush.android.intent.NOTIFICATION_OPENED",
+                "cn.jpush.android.intent.CONNECTION"  }, Categories = new string[] { "com.evoyo.home" })]
     public class JpushNotificationReceiver : BroadcastReceiver
     {
         private static string TAG = "JpushNotificationReceiver";
@@ -215,8 +248,8 @@
                 //鎺ユ敹鍒版帹閫佷笅鏉ョ殑鑷畾涔夋秷鎭�
                 else if (JPushInterface.ActionMessageReceived == intent.Action)
                 {
-                    bundle.GetString(JPushInterface.ExtraMessage);
-                 }
+                    bundle.GetString(JPushInterface.ExtraMessage);
+                }
                 else
                 {
                 }
@@ -251,36 +284,83 @@
         /// <param name="bundle">Bundle.</param>
         private void OpenNotification(Context context, Bundle bundle)
         {
+
+            Intent i = new Intent(context, typeof(BaseActivity));//Intent intent=new Intent( 璧峰缁勪欢瀵硅薄 , 鐩爣 Service.class);
+            i.PutExtras(bundle);
+            i.SetFlags(ActivityFlags.NewTask);
+            context.StartActivity(i);
+
             String extras = bundle.GetString(JPushInterface.ExtraExtra);
-            String myValue = "";
+            //String myValue = "";
             try
             {
-                JSONObject extrasJson = new JSONObject(extras);
-                myValue = extrasJson.OptString("myKey");
+                VideoMethod(extras);
+                //JSONObject extrasJson = new JSONObject(extras);
+                //myValue = extrasJson.OptString("myKey");
+
             }
             catch (Exception e)
             {
                 System.Console.WriteLine(TAG, "Unexpected: extras is not a valid json", e);
                 return;
+            }
+
+            //if (TYPE_THIS.equals(myValue))
+            //{
+            //Intent mIntent = new Intent(context, ThisActivity.class);
+            //mIntent.putExtras(bundle);
+            //mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            //context.startActivity(mIntent);
+            //}
+            //else if (TYPE_ANOTHER.equals(myValue))
+            //{
+            //Intent mIntent = new Intent(context, AnotherActivity.class);
+            //mIntent.putExtras(bundle);
+            //mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            //context.startActivity(mIntent);
+            //}
+        }
+
+        /// <summary>
+        /// android閫氱煡鏍忕偣鍑绘墦寮�鍙瀵硅鐨勬柟娉�
+        /// </summary>
+        /// <param name="hiddenJson">浜戠鎺ㄨ繃鏉ョ殑鏁版嵁</param>
+        private void VideoMethod(string hiddenJson)
+        {
+            var hiddanJson = Newtonsoft.Json.Linq.JObject.Parse(hiddenJson);
+            if (hiddanJson == null)
+            {
+                return;
             }
-            Intent i = new Intent(context, typeof(BaseActivity));//Intent intent=new Intent( 璧峰缁勪欢瀵硅薄 , 鐩爣 Service.class);
-            i.PutExtras(bundle);
-            i.SetFlags(ActivityFlags.NewTask);
-            context.StartActivity(i);
-            //if (TYPE_THIS.equals(myValue))
-            //{
-            //Intent mIntent = new Intent(context, ThisActivity.class);
-            //mIntent.putExtras(bundle);
-            //mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-            //context.startActivity(mIntent);
-            //}
-            //else if (TYPE_ANOTHER.equals(myValue))
-            //{
-            //Intent mIntent = new Intent(context, AnotherActivity.class);
-            //mIntent.putExtras(bundle);
-            //mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-            //context.startActivity(mIntent);
-            //}
+            var json = Newtonsoft.Json.Linq.JObject.Parse(hiddanJson["HiddanJson"].ToString());
+            if (json == null)
+            {
+                return;
+            }
+            Shared.Phone.VideoPhone.ESVideoInfo eSVideoInfo = new Shared.Phone.VideoPhone.ESVideoInfo();
+            if (json["uuid"].ToString().Contains(","))
+            {
+                var uuid = json["uuid"].ToString().Split(',');
+                eSVideoInfo.ESVideoUUID = uuid[0];
+
+            }
+            else
+            {
+                eSVideoInfo.ESVideoUUID = json["uuid"].ToString();
+            }
+
+            eSVideoInfo.DeviceName = Language.StringByID(Shared.R.MyInternationalizationString.theOutdoorUnit);
+            eSVideoInfo.ESRoomID = int.Parse(json["roomno"].ToString());
+            if (!string.IsNullOrEmpty(json["unitno"].ToString()))
+            {
+                string str = json["unitno"].ToString();
+                string str1 = str.Substring(0, 2).TrimStart('0');
+                string str2 = str.Substring(2, 2).TrimStart('0');
+                eSVideoInfo.RoomName = str1 + Language.StringByID(Shared.R.MyInternationalizationString.dong) + str2 + Language.StringByID(Shared.R.MyInternationalizationString.unit);
+            }
+
+            Shared.Phone.VideoPhone.ESVideo.ShowESvideoVideoIntercom(eSVideoInfo);
+
         }
     }
 }

--
Gitblit v1.8.0