예제 #1
0
        public override bool OnCreate()
        {
            AGConnectServicesConfig config = AGConnectServicesConfig.FromContext(Context);

            config.OverlayWith(new HmsLazyInputStream(Context));
            return(false);
        }
        private void DetectUser()
        {
            string appid = AGConnectServicesConfig.FromContext(Activity).GetString("client/app_id");

            SafetyDetect.GetClient(Activity).UserDetection(appid)
            .AddOnSuccessListener(new OnSuccessListener((Result) =>
            {
                UserDetectResponse userDetectResponse = (UserDetectResponse)Result;
                Log.Info("DetectUser", $"User detection succeed, response {userDetectResponse.ResponseToken}");
                Toast.MakeText(Activity.ApplicationContext, $"User detection succeed.", ToastLength.Short).Show();
            }))
            .AddOnFailureListener(new OnFailureListener((Result) =>
            {
                string errorMessage = null;
                if (Result is ApiException exception)
                {
                    errorMessage = $"{SafetyDetectStatusCodes.GetStatusCodeString(exception.StatusCode)}: {exception.Message}";
                }
                else
                {
                    errorMessage = ((Java.Lang.Exception)Result).Message;
                }
                Log.Error("DetectUser", errorMessage);
                Toast.MakeText(Activity.ApplicationContext, $"User detection failed! Message: {errorMessage}", ToastLength.Short).Show();
                // If value is 19800, this means Fake user detection failed. It also be throwed when user clicks cancel button.
            }));
        }
예제 #3
0
        /*
         * GetToken(String appId, String scope), This method is used to obtain a token required for accessing HUAWEI Push Kit.
         * If there is no local AAID, this method will automatically generate an AAID when it is called because the Huawei Push server needs to generate a token based on the AAID.
         * This method is a synchronous method, and you cannot call it in the main thread. Otherwise, the main thread may be blocked.
         */
        private void GetToken()
        {
            ShowLog("getToken:begin");

            System.Threading.Thread thread = new System.Threading.Thread(() =>
            {
                try
                {
                    string appid = AGConnectServicesConfig.FromContext(this).GetString("client/app_id");
                    string token = HmsInstanceId.GetInstance(this).GetToken(appid, "HCM");
                    Log.Info(TAG, "token = " + token);

                    if (!TextUtils.IsEmpty(token))
                    {
                        SendRegTokenToServer(token);
                    }

                    ShowLog("get token:" + token);
                }
                catch (Exception e)
                {
                    Log.Info(TAG, e.ToString());
                    ShowLog("get token failed, " + e);
                }
            }

                                                                         );
            Log.Info(TAG, "start the thread");
            thread.Start();
        }
예제 #4
0
        protected override void AttachBaseContext(Context context)
        {
            base.AttachBaseContext(context);
            AGConnectServicesConfig config = AGConnectServicesConfig.FromContext(context);

            config.OverlayWith(new HmsLazyInputStream(context));
        }
예제 #5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            btnMarkersDemo  = FindViewById <Button>(Resource.Id.btnMarkersDemo);
            btnPolylineDemo = FindViewById <Button>(Resource.Id.btnPolylineDemo);
            btnPolygonDemo  = FindViewById <Button>(Resource.Id.btnPolygonDemo);
            btnCircleDemo   = FindViewById <Button>(Resource.Id.btnCircleDemo);
            btnOverlayDemo  = FindViewById <Button>(Resource.Id.btnOverlayDemo);

            btnMarkersDemo.Click  += btnMarkersDemo_Click;
            btnPolylineDemo.Click += btnPolylineDemo_Click;
            btnPolygonDemo.Click  += btnPolygonDemo_Click;
            btnCircleDemo.Click   += btnCircleDemo_Click;
            btnOverlayDemo.Click  += btnOverlayDemo_Click;

            checkPermission(new string[] {
                Android.Manifest.Permission.WriteExternalStorage,
                Android.Manifest.Permission.ReadExternalStorage,
                Android.Manifest.Permission.AccessCoarseLocation,
                Android.Manifest.Permission.AccessFineLocation,
                Android.Manifest.Permission.Internet
            }, 100);

            AGConnectServicesConfig config = AGConnectServicesConfig.FromContext(ApplicationContext);
        }
예제 #6
0
        public override void OnCreate()
        {
            base.OnCreate();
            var config = AGConnectServicesConfig.FromContext(this);

            config.OverlayWith(new MyLazyInputStream(this));
        }
예제 #7
0
        public void GetToken()
        {
            string appId = AGConnectServicesConfig.fromContext(new Context()).getString("client/app_id");
            string token = HmsInstanceId.getInstance(new Context()).getToken(appId, "HCM");

            TestTip.Inst.ShowText(token);
            GUIUtility.systemCopyBuffer = token;
        }
예제 #8
0
        private string ReadApiKeyFromConfig(AGConnectServicesConfig config)
        {
            string clientConfig = config.GetString("client");

            return(new GoogleGson.JsonParser()
                   .Parse(clientConfig)
                   .AsJsonObject
                   .Get("api_key")
                   .AsString);
        }
예제 #9
0
        public override bool OnCreate()
        {
            Log.Info("XamarinCustomProvider", "OnCreate : Start");

            var config = AGConnectServicesConfig.FromContext(Context);

            config.OverlayWith(new HmsLazyInputStream(Context));

            Log.Info("XamarinCustomProvider", "OnCreate : End");
            return(false);
        }
예제 #10
0
        protected override void AttachBaseContext(Context context)
        {
            base.AttachBaseContext(context);
            AGConnectServicesConfig config = AGConnectServicesConfig.FromContext(context);

            config.OverlayWith(new HmsLazyInputStream(context));

            // Read api_key entry from config
            // and assign to apiKey property
            apiKey = ReadApiKeyFromConfig(config);
        }
예제 #11
0
        private void SysIntegrity()
        {
            byte[] nonce = new byte[24];
            string appid = AGConnectServicesConfig.FromContext(Activity).GetString("client/app_id");

            SafetyDetect.GetClient(Activity).SysIntegrity(nonce, appid).AddOnSuccessListener(new OnSuccessListener((Result) =>
            {
                SysIntegrityResp response = (SysIntegrityResp)Result;
                string jwStr         = response.Result;
                string[] jwsSplit    = jwStr.Split(".");
                string jwsPayloadStr = jwsSplit[1];
                byte[] data          = Convert.FromBase64String(jwsPayloadStr);
                string jsonString    = Encoding.UTF8.GetString(data);
                JSONObject jObject   = new JSONObject(jsonString);
                Log.Info("SysIntegrity", jsonString.Replace(",", ",\n"));

                string basicIntegrityText = null;
                try
                {
                    bool basicIntegrity = jObject.GetBoolean("basicIntegrity");
                    if (basicIntegrity)
                    {
                        theButton.SetBackgroundResource(Resource.Drawable.btn_round_green);
                        basicIntegrityText = "Basic Integrity is Success.";
                    }
                    else
                    {
                        theButton.SetBackgroundResource(Resource.Drawable.btn_round_red);
                        basicIntegrityText  = "Basic Integrity is Failure.";
                        adviceTextView.Text = $"Advice: {jObject.GetString("advice")}";
                    }
                }
                catch (JSONException e)
                {
                    Android.Util.Log.Error("SysIntegrity", e.Message);
                }
                basicIntegrityTextView.Text = basicIntegrityText;
                theButton.SetText(Resource.String.rerun);
            })).AddOnFailureListener(new OnFailureListener((Result) =>
            {
                string errorMessage = null;
                if (Result is ApiException exception)
                {
                    errorMessage = $"{SafetyDetectStatusCodes.GetStatusCodeString(exception.StatusCode)}: {exception.Message}";
                }
                else
                {
                    errorMessage = ((Java.Lang.Exception)Result).Message;
                }
                Log.Error("SysIntegrity", errorMessage);
                theButton.SetBackgroundResource(Resource.Drawable.btn_round_yellow);
            }));
        }
예제 #12
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.activity_main);
            BottomNavigationView navigation = FindViewById <BottomNavigationView>(Resource.Id.navigation);

            navigation.SetOnNavigationItemSelectedListener(this);
            AGConnectServicesConfig config = AGConnectServicesConfig.FromContext(this);

            SetMap();
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            MapsInitializer.Initialize(this);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);
            AGConnectServicesConfig config = AGConnectServicesConfig.FromContext(ApplicationContext);

            config.OverlayWith(new HmsLazyInputStream(this));
            Com.Huawei.Agconnect.AGConnectInstance.Initialize(this);

            checkPermission(new string[] {
                Android.Manifest.Permission.WriteExternalStorage,
                Android.Manifest.Permission.ReadExternalStorage,
                Android.Manifest.Permission.AccessCoarseLocation,
                Android.Manifest.Permission.AccessFineLocation,
                Android.Manifest.Permission.Internet
            }, 100);

            //get mapview instance

            mMapView = FragmentManager.FindFragmentById <MapFragment>(Resource.Id.mapview);

            btnMarkersDemo         = FindViewById <Button>(Resource.Id.btnMarkersDemo);
            btnPolylineDemo        = FindViewById <Button>(Resource.Id.btnPolylineDemo);
            btnPolygonDemo         = FindViewById <Button>(Resource.Id.btnPolygonDemo);
            btnCircleDemo          = FindViewById <Button>(Resource.Id.btnCircleDemo);
            btnOverlayDemo         = FindViewById <Button>(Resource.Id.btnOverlayDemo);
            btntype                = FindViewById <Button>(Resource.Id.btntype);
            btntype.Click         += OnClick;
            btnMarkersDemo.Click  += btnMarkersDemo_Click;
            btnPolylineDemo.Click += btnPolylineDemo_Click;
            btnPolygonDemo.Click  += btnPolygonDemo_Click;
            btnCircleDemo.Click   += btnCircleDemo_Click;
            btnOverlayDemo.Click  += btnOverlayDemo_Click;

            context   = this;
            viewModel = new MainViewModel();

            Bundle mapViewBundle = null;

            if (savedInstanceState != null)
            {
                mapViewBundle = savedInstanceState.GetBundle(MAPVIEW_BUNDLE_KEY);
            }

            mMapView.OnCreate(mapViewBundle);
            //get map instance
            RunOnUiThread(() => mMapView.GetMapAsync(this));
        }
예제 #14
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            AGConnectServicesConfig config = AGConnectServicesConfig.FromContext(ApplicationContext);

            Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);
            SafetyDetect.GetClient(this).InitUserDetect();

            FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.fab);

            fab.Click += FabOnClick;
        }
        private void CallUrlCheckApi()
        {
            string   appid      = AGConnectServicesConfig.FromContext(Activity).GetString("client/app_id");
            EditText editText   = Activity.FindViewById <EditText>(Resource.Id.fg_call_urlCheck_text);
            string   realUrl    = editText.Text.Trim();
            TextView textResult = Activity.FindViewById <TextView>(Resource.Id.fg_call_urlResult);

            client.UrlCheck(realUrl, appid, UrlCheckThreat.Malware, UrlCheckThreat.Phishing)
            .AddOnSuccessListener(new OnSuccessListener((Result) =>
            {
                /**
                 * Called after successfully communicating with the SafetyDetect API.
                 * The #onSuccess callback receives an
                 * {@link Com.Huawei.Hms.Support.Api.Entity.Safetydetect.UrlCheckResponse} that contains a
                 * list of UrlCheckThreat that contains the threat type of the Url.
                 *  Indicates communication with the service was successful.
                 *  Identify any detected threats.
                 *  Get UrlCheckResponse property of UrlCheckResponse then you can get List<UrlCheckThreat> .
                 *  If List<UrlCheckThreat> is empty , that means no threats found , else that means threats found
                 */
                List <UrlCheckThreat> list = ((UrlCheckResponse)Result).GetUrlCheckResponse().ToList();
                if (list.Count == 0)
                {
                    textResult.Text = "No threats found.";
                    Log.Info("UrlCheck", $"{textResult.Text}");
                }
                else
                {
                    textResult.Text = "Threats found!";
                    Log.Info("UrlCheck", $"{textResult.Text}");
                    foreach (UrlCheckThreat line in list)
                    {
                        Log.Info("UrlCheck", $"Threat type: {line.UrlCheckResult}");
                    }
                }
            })).AddOnFailureListener(new OnFailureListener((Result) =>
            {
                string errorMessage = null;
                if (Result is ApiException exception)
                {
                    errorMessage = $"{SafetyDetectStatusCodes.GetStatusCodeString(exception.StatusCode)}: {exception.Message}";
                }
                Log.Error("UrlCheck", errorMessage);
            }));
        }
예제 #16
0
 private void GetToken()
 {
     System.Threading.Thread thread = new System.Threading.Thread(() =>
     {
         try
         {
             string appid = AGConnectServicesConfig.FromContext(this).GetString("client/app_id");
             string token = HmsInstanceId.GetInstance(this).GetToken(appid, "HCM");
             Log.Info(TAG, "token = " + token);
         }
         catch (Java.Lang.Exception e)
         {
             Log.Info(TAG, e.ToString());
         }
     }
                                                                  );
     Log.Info(TAG, "start the thread");
     thread.Start();
 }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            AGConnectServicesConfig config = AGConnectServicesConfig.FromContext(ApplicationContext);

            fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this);
            mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.mapfragment);
            mapFragment.GetMapAsync(this);


            FindViewById <Button>(Resource.Id.btnGeoWithAddress).Click += btnGeoWithAddress_Click;
            FindViewById <Button>(Resource.Id.btnClearMap).Click       += btnClearMap_Click;
            radiusBar = FindViewById <SeekBar>(Resource.Id.radiusBar);
            radiusBar.ProgressChanged += radiusBar_ProgressChanged;;
            RequestPermissions();
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View   view  = inflater.Inflate(Resource.Layout.fg_others, container, false);
            string appid = AGConnectServicesConfig.FromContext(Activity).GetString("client/app_id");

            view.FindViewById <Button>(Resource.Id.fg_wifidetect).SetOnClickListener(this);
            view.FindViewById <Button>(Resource.Id.fg_userdetect).SetOnClickListener(this);
            view.FindViewById <Button>(Resource.Id.fg_risktoken).SetOnClickListener(this);

            client = SafetyDetect.GetClient(Activity);

            client.InitUserDetect()
            .AddOnSuccessListener(new OnSuccessListener((Result) => { Log.Info("InitUserDetect", "InitUserDetect is succeeded."); }))
            .AddOnFailureListener(new OnFailureListener((Result) => { Log.Error("InitUserDetect", "InitUserDetect is failed."); }));
            client.InitAntiFraud(appid)
            .AddOnSuccessListener(new OnSuccessListener((Result) => { Log.Info("InitAntiFraud", "InitAntiFraud is succeeded."); }))
            .AddOnFailureListener(new OnFailureListener((Result) => { Log.Error("InitAntiFraud", "InitAntiFraud is failed."); }));

            return(view);
        }
예제 #19
0
        /// <summary>
        /// Obtains a token required for accessing Push Kit.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnClickGetToken(object sender, EventArgs e)
        {
            string MethodName = "GetToken";
            Thread thread     = new Thread(() =>
            {
                try
                {
                    string appid = AGConnectServicesConfig.FromContext(this).GetString("client/app_id");
                    string token = HmsInstanceId.GetInstance(this).GetToken(appid, HmsMessaging.DefaultTokenScope);

                    log.Info(MethodName, token);
                }
                catch (ApiException exception)
                {
                    log.Error(MethodName, $"Error/Exception: {exception.Message}");
                }
            });

            thread.Start();
        }
예제 #20
0
 /**
  * void DeleteToken(String appId, String scope) throws ApiException
  * This method is used to obtain a token. After a token is deleted, the corresponding AAID will not be deleted.
  * This method is a synchronous method. Do not call it in the main thread. Otherwise, the main thread may be blocked.
  */
 private void DeleteToken()
 {
     ShowLog("deleteToken:begin");
     System.Threading.Thread thread = new System.Threading.Thread(() =>
     {
         try
         {
             string appid = AGConnectServicesConfig.FromContext(this).GetString("client/app_id");
             HmsInstanceId.GetInstance(this).DeleteToken(appid, "HCM");
             Log.Info(TAG, "deleteToken success.");
             ShowLog("deleteToken success");
         }
         catch (ApiException e)
         {
             Log.Error(TAG, "deleteToken failed." + e);
             ShowLog("deleteToken failed." + e);
         }
     });
     Log.Info(TAG, "start the thread");
     thread.Start();
 }
예제 #21
0
        public void DeleteToken()
        {
            string appId = AGConnectServicesConfig.fromContext(new Context()).getString("client/app_id");

            HmsInstanceId.getInstance(new Context()).deleteToken(appId, "HCM");
        }
예제 #22
0
 public override bool OnCreate()
 {
     AGConnectServicesConfig config = AGConnectServicesConfig.FromContext(Context);
     config.OverlayWith(new HmsLazyInputStream(Context));
     return false; throw new NotImplementedException();
 }