From 25429f085093d89d543a0b90e30d0d62d1b7dac9 Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期二, 30 八月 2022 09:37:38 +0800
Subject: [PATCH] 合并了IOS的代码

---
 ZigbeeApp/GateWay.Droid/Application.cs |  456 +++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 270 insertions(+), 186 deletions(-)

diff --git a/ZigbeeApp/GateWay.Droid/Application.cs b/ZigbeeApp/GateWay.Droid/Application.cs
old mode 100755
new mode 100644
index 2cdce88..11b2585
--- a/ZigbeeApp/GateWay.Droid/Application.cs
+++ b/ZigbeeApp/GateWay.Droid/Application.cs
@@ -17,22 +17,22 @@
 using Com.Tencent.MM.Sdk.Openapi;
 using ZXing.Mobile;
 using System.IO;
-
+using GateWay.Droid.JPush;
+
 namespace com.hdl.home
 {
-
     [Activity(Name = "com.hdl.home.wxapi.WXEntryActivity", Exported = true, Theme = "@android:style/Theme.Translucent", LaunchMode = Android.Content.PM.LaunchMode.SingleTask)]
     class WXEntryActivity : Android.App.Activity, IWXAPIEventHandler
     {
         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;
@@ -51,64 +51,124 @@
                         break;
                     default:
                         RespAction?.Invoke(null);
-                        break;
-
-                    //case SendAuth.Resp.InnerErrCode.ErrUserCancel:
-                    //    break;
-                    //case SendAuth.Resp.InnerErrCode.ErrAuthDenied:
-                    //    break;
-
+                        break;
+
+                        //case SendAuth.Resp.InnerErrCode.ErrUserCancel:
+                        //    break;
+                        //case SendAuth.Resp.InnerErrCode.ErrAuthDenied:
+                        //    break;
+
                 }
-            }
-            
+            }
+
             this.Finish();
         }
         //IWXAPI api;
         protected override void OnCreate(Bundle savedInstanceState)
         {
-            base.OnCreate(savedInstanceState);
-            // 閫氳繃WXAPIFactory宸ュ巶锛岃幏鍙朓WXAPI鐨勫疄渚�
-            //api = WXAPIFactory.CreateWXAPI(this, "wx2ec8f53f6fa36e82", false);
-
-            // 灏嗗簲鐢ㄧ殑appId娉ㄥ唽鍒板井淇�
-            //api.RegisterApp("wx2ec8f53f6fa36e82");
-
-          com.hdl.home.Application.api.HandleIntent(Intent, this);
+            base.OnCreate(savedInstanceState);
+            // 閫氳繃WXAPIFactory宸ュ巶锛岃幏鍙朓WXAPI鐨勫疄渚�
+            //api = WXAPIFactory.CreateWXAPI(this, "wx2ec8f53f6fa36e82", false);
+
+            // 灏嗗簲鐢ㄧ殑appId娉ㄥ唽鍒板井淇�
+            //api.RegisterApp("wx2ec8f53f6fa36e82");
+
+            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");
+    /// <summary>
+	/// 璁惧畾涓洪粯璁ゅ惎鍔ㄧ殑Application
+	/// </summary>
+	[Android.App.Application]
+    public class Application : Android.App.Application
+    {
+        public Application(IntPtr handle, Android.Runtime.JniHandleOwnership ownerShip) : base(handle, ownerShip) { }
+
+        /// <summary>
+        /// 妫�娴嬪唴瀛樻硠闇茬殑涓滆タ
+        /// </summary>
+        //private Square.LeakCanary.RefWatcher _refWatcher;
+
+        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);
+
+            //妫�娴嬪唴瀛樻硠闇茬殑涓滆タ
+            //if (Square.LeakCanary.LeakCanaryXamarin.IsInAnalyzerProcess(this) == false)
+            //{
+            //    _refWatcher = Square.LeakCanary.LeakCanaryXamarin.Install(this);
+            //    _refWatcher.Watch(this);
             //}
-            initAll();鈥�            base.OnCreate();
-            // 閫氳繃WXAPIFactory宸ュ巶锛岃幏鍙朓WXAPI鐨勫疄渚�
-            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;
 
-       internal static IWXAPI api;
-
-        public static void WXLogin() {
+        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()
+        {
+            //鍙栨秷灞忓箷甯镐寒
+            BaseActivity.KeepScreenON = false;
+            //闅愯棌搴曢儴杞寜閿�
+            BaseActivity.IsHideVirualButtons = true;
+
             //璁剧疆鏋佸厜璋冭瘯妯″紡锛屼负false鏃跺彧鎵撳嵃璀﹀憡淇℃伅
             // System.Console.WriteLine($"AAA : {System.DateTime.Now.ToString()}");
-#if Release鈥�            JPushInterface.SetDebugMode(false);
-            //淇濆瓨鎵嬫満鍚嶇О鍒版湰鍦版枃浠�
-            //System.Console.WriteLine($"BBB : {System .DateTime .Now .ToString ()}");
 
-            JPushInterface.Init(this);
-            //System.Console.WriteLine($"CCC : {System.DateTime.Now.ToString()}");
-#endif
-            BaseActivity.BackKeyAction = () => {
+            JPushInterface.SetDebugMode(true);
+            JPushInterface.Init(this);
+            string registration_id = JPushInterface.GetRegistrationID(this);
+
+            BaseActivity.BackKeyAction = () =>
+            {
                 try
                 {
                     if (Shared.Common.CommonPage.BackKeyCanClick == false)
@@ -145,167 +205,187 @@
                     Console.WriteLine("Remove PageLayout Children!!!!");
                     HomePage.Instance.GetChildren(HomePage.Instance.ChildrenCount - 1).RemoveFromParent();
                     Console.WriteLine("Remove PageLayout Children End!!!!");
+                }
+                else if (Shared.Common.CommonPage.Instance.ChildrenCount > 2)
+                {
+                    //杩欓噷鍙搴旂櫥闄嗙晫闈㈢殑
+                    Shared.Common.CommonPage.Instance.GetChildren(Shared.Common.CommonPage.Instance.ChildrenCount - 1).RemoveFromParent();
                 }
                 else
                 {
                     BaseActivity.VerifyDateTime = DateTime.MaxValue;
                     Console.WriteLine("BaseActivity VerifyDateTime Max!!!!");
                 }
-            };
-鈥�            BaseActivity.OnCreateActoin += (activity, application) => {
+            };
+            BaseActivity.OnCreateActoin += (activity, application) =>
+            {
                 Shared.Application.FontSize = 12;
-                AppCenter.Start("4802834a-e7e9-4dd8-93f1-c2f88f0bd464", typeof(Analytics), typeof(Crashes));鈥�#if Release鈥�                //淇濆瓨鑾峰彇鐨勬瀬鍏夋湇鍔″櫒涓婄殑娉ㄥ唽ID鍒版湰鍦版枃浠垛��                var registrationId = JPushInterface.GetRegistrationID(activity);
+                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();鈥�                }鈥�#endif鈥�            };鈥�            BaseActivity.RefreshUIAction += (activity) => {鈥�                Shared.Language.CurrentLanguage = "Chinese";鈥�                Shared.Common.CommonPage.Instance.Show();鈥�             };鈥�            BaseActivity.OnResumeAction += (activity) => {鈥�             };鈥�            BaseActivity.NetworkStateChanged += (v) =>鈥�            {鈥�                //缃戠粶鐘舵�佸彉鍖栧鐞嗕簨浠�
-                Shared.Common.CommonPage.nowNetworkMode = 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;鈥�        }
-    }
-
-    public class JpushNotificationReceiver : BroadcastReceiver
-    {
-        private static string TAG = "JpushNotificationReceiver";
-        private NotificationManager nm;
-        static string ACTION = "android.intent.action.BOOT_COMPLETED";
-        public override void OnReceive(Context context, Intent intent)
-        {
-            if (nm == null)
-            {
-                nm = (NotificationManager)context.GetSystemService(Context.NotificationService);
-            }
-            //base.OnReceive (context, intent);
-            try
-            {
-                Bundle bundle = intent.Extras;
-                if (intent.Action == ACTION)
-                {
-                    //寮�鏈鸿嚜鍔ㄦ湇鍔¤嚜鍔ㄥ惎鍔�,PushService鏄鍚姩鐨勬湇鍔�
-                    Intent service = new Intent(context, typeof(PushService));
-                    context.StartService(service);
-                }
-
-                //鎺ユ敹Registration Id
-                if (JPushInterface.ActionRegistrationId == intent.Action)
+                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)
                 {
-                    string regId = bundle.GetString(JPushInterface.ExtraRegistrationId);
-                    if (!string.IsNullOrEmpty(regId))
-                    {
-                        Shared.Common.Config.Instance.RegistrationID = regId;
-                        Shared.Common.Config.Instance.Save();
-                    }
-                }
-                //鐢ㄦ埛鐐瑰嚮鎵撳紑浜嗛�氱煡
-                else if (JPushInterface.ActionNotificationOpened == intent.Action)
-                {
-                    OpenNotification(context, bundle);
-                }
-                //鎺ュ彈鍒版帹閫佷笅鏉ョ殑閫氱煡
-                else if (JPushInterface.ActionNotificationReceived == intent.Action)
-                {
-                    //int notifactionId = bundle.GetInt(JPushInterface.ExtraNotificationId);
-                    ReceivingNotification(context, bundle);
-                    //Shared.Common.CommonPage.Instance.SingOut();
-                }
-                //鎺ユ敹鍒版帹閫佷笅鏉ョ殑鑷畾涔夋秷鎭�
-                else if (JPushInterface.ActionMessageReceived == intent.Action)
-                {
-                    bundle.GetString(JPushInterface.ExtraMessage);
-                 }
-                else
-                {
-                }
-            }
-            catch (System.Exception e)
-            {
-
-                System.Console.WriteLine("鏋佸厜鎺ㄩ�佸嚭閿�:" + e.Message);
-            }
-        }
+                    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>
-        /// <param name="bundle">Bundle.</param>
-        private void ReceivingNotification(Context context, Bundle bundle)
-        {
-            String title = bundle.GetString(JPushInterface.ExtraNotificationTitle);
-            System.Console.WriteLine(TAG, " title : " + title);
-            String message = bundle.GetString(JPushInterface.ExtraAlert);
-            System.Console.WriteLine(TAG, "message : " + message);
-            String extras = bundle.GetString(JPushInterface.ExtraExtra);
-            System.Console.WriteLine(TAG, "extras : " + extras);
-
-            //澶勭悊鏋佸厜娑堟伅鎺ㄩ�佺殑閫昏緫鍑芥暟
-            Shared.Phone.UserCenter.HdlJiguangMsgPushLogic.Current.AdjustJiguangMsgPush(title, message, extras);
-        }
+        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>
+        /// 缃戠粶鏄惁杩炴帴
+        /// </summary
+        /// <returns><c>true</c>, if wifi connected was ised, <c>false</c> otherwise.</returns>
         /// <param name="context">Context.</param>
-        /// <param name="bundle">Bundle.</param>
-        private void OpenNotification(Context context, Bundle bundle)
-        {
-            String extras = bundle.GetString(JPushInterface.ExtraExtra);
-            String myValue = "";
-            try
-            {
-                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;
-            }
-            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);
-            //}
+        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;
         }
-    }
+    }
 }
 
 namespace Shared
 {
     public static class QRCode
     {
-        static ZXing.Mobile.MobileBarcodeScanner scanner;
-        public static void ScanQRcode(Action<string> action)
-        {
-            ((BaseActivity)Shared.Application.Activity).SetCamera(async (obj) => {
-                if (obj)
-                {
-                    if (scanner == null)
-                    {
-                        MobileBarcodeScanner.Initialize(Shared.Application.Activity.Application);
-                        scanner = new ZXing.Mobile.MobileBarcodeScanner();
-                    }
-
-                    var result = await scanner.Scan();
-
-                    if (result != null)
-                        action?.Invoke(result.Text);
-                    else
-                        action?.Invoke(null);
-
-                }
-                else
-                {
-                    action?.Invoke(null);
-                }
-            });
+        static ZXing.Mobile.MobileBarcodeScanner scanner;
+        public static void ScanQRcode(Action<string> action, string cancel = "鍙栨秷", string flashText = "闂厜鐏�", string titleText = "浜岀淮鐮佹壂鎻�")
+        {
+            ((BaseActivity)Shared.Application.Activity).SetCamera(async (obj) =>
+            {
+                if (obj)
+                {
+                    if (scanner == null)
+                    {
+                        MobileBarcodeScanner.Initialize(Shared.Application.Activity.Application);
+                        var mZXingCustomScanView = new GateWay.Droid.ZXingCustomScanView(Shared.Application.Activity.Application);
+                        mZXingCustomScanView.cancelTextView.Text = cancel;
+                        mZXingCustomScanView.flashTextView.Text = flashText;
+                        mZXingCustomScanView.titleTextView.Text = titleText;
+                        var bOn = false;
+                        scanner = new ZXing.Mobile.MobileBarcodeScanner()
+                        {
+                            UseCustomOverlay = true,
+                            CustomOverlay = mZXingCustomScanView
+                        };
+
+                        mZXingCustomScanView.OnCancel += () =>
+                        {
+
+                            scanner?.Cancel();
+                        };
+
+                        mZXingCustomScanView.OnTorch += () =>
+                        {
+                            bOn = !bOn;
+                            scanner?.Torch(bOn);
+                        };
+                    }
+
+                    var result = await scanner.Scan();
+
+                    if (result != null)
+                        action?.Invoke(result.Text);
+                    else
+                        action?.Invoke(null);
+
+                }
+                else
+                {
+                    action?.Invoke(null);
+                }
+            });
         }
 
         public static byte[] BytesFromText(string text, int width = 300, int height = 300)
@@ -330,5 +410,9 @@
                 return stream.ToArray();
             }
         }
+
+      
     }
+
+   
 }

--
Gitblit v1.8.0