更多关于请求接口的详细信息可以参考API参考。
检测尝试连接的WIFI及路由器特征,分析当前尝试访问的网络情况,通过聚类分析,实时反馈Wifi检测结果,帮助开发者防范来自恶意Wifi的恶意行为攻击。
开发者集成WifiDetect接口,当应用获取尝试连接的WIFI存在ARP攻击、中间人攻击、DNS劫持等攻击时,开发者可以阻断操作或者进一步让用户认证确认。
请参考:开发流程
使用 Safety Detect WifiDetect API 之前,必须确保在用户设备上安装了正确版本的 HMS 服务。如果安装了不正确的版本,则您的应用可能会在调用 API 后停止响应。如果您的应用检测到安装了错误的版本,则应要求用户在其设备上更新 HMS。
要检查已安装的 HMS 版本是否与您使用的Android SDK版本兼容,请调用 isHuaweiMobileServicesAvailable() 方法,如以下代码片段所示:
- if (HuaweiApiAvailability.getInstance().isHuaweiMobileServicesAvailable(context) == ConnectionResult.SUCCESS){
- // The SafetyDetect SysIntegrity API is available.
- } else {
- // Prompt user to update HMS.
- }
- /*
- * Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- package com.huawei.hms.safetydetect.sample;
- import com.huawei.hmf.tasks.OnFailureListener;
- import com.huawei.hmf.tasks.OnSuccessListener;
- import com.huawei.hms.common.ApiException;
- import com.huawei.hms.support.api.entity.safetydetect.WifiDetectResponse;
- import com.huawei.hms.support.api.safetydetect.SafetyDetect;
- import com.huawei.hms.support.api.safetydetect.SafetyDetectStatusCodes;
- import android.app.Fragment;
- import android.util.Log;
- import android.view.View;
- /**
- * An example of how to use AppsCheck Service API.
- * Note that you have to configure an AppId for SafetyDetect Service first.
- */
- public class SafetyDetectWifiDetectAPIFragment extends Fragment implements View.OnClickListener {
- private void invokeGetWifiDetectStatus() {
- Log.i(TAG, "Start to getWifiDetectStatus!");
- SafetyDetectClient wifidetectClient = SafetyDetect.getClient(MainActivity.this);
- Task task = wifidetectClient.getWifiDetectStatus();
- task.addOnSuccessListener(new OnSuccessListener<WifiDetectResponse>() {
- @Override
- public void onSuccess(WifiDetectResponse wifiDetectResponse) {
- int wifiDetectStatus = wifiDetectResponse.getWifiDetectStatus();
- Log.i(TAG, "\n-1 :获取WiFi状态失败\n" + "0 :未连接WIFI\n" + "1 :当前连接的WIFI安全\n" + "2 :当前连接的WIFI不安全.");
- Log.i(TAG, "wifiDetectStatus is: " + wifiDetectStatus);
- }
- }).addOnFailureListener(new OnFailureListener() {
- @Override
- public void onFailure(Exception e) {
- if (e instanceof ApiException) {
- ApiException apiException = (ApiException) e;
- Log.e(TAG,
- "Error: " + apiException.getStatusCode() + ":"
- + SafetyDetectStatusCodes.getStatusCodeString(apiException.getStatusCode()) + ": "
- + apiException.getStatusMessage());
- } else {
- Log.e(TAG, "ERROR! " + e.getMessage());
- }
- }
- });
- }
- }
更多关于请求接口的详细信息可以参考API参考。