{"id":667,"date":"2023-04-02T02:20:07","date_gmt":"2023-04-01T18:20:07","guid":{"rendered":"http:\/\/gjweb.top\/?p=667"},"modified":"2023-04-02T02:20:08","modified_gmt":"2023-04-01T18:20:08","slug":"%e5%8a%a8%e6%80%81%e8%8e%b7%e5%8f%96wifi%e5%90%8d%e7%a7%b0","status":"publish","type":"post","link":"https:\/\/gjweb.top\/?p=667","title":{"rendered":"\u52a8\u6001\u83b7\u53d6wifi\u540d\u79f0"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u4f7f\u7528\u7b2c\u4e09\u65b9\u63d2\u4ef6<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>connectivity_plus \u7528\u6765\u76d1\u542c\u5207\u6362\u7f51\u7edc\u7684\u53d8\u5316<\/li><li>network_info_plus \u7528\u6765\u83b7\u53d6 wifi \u7684\u540d\u79f0<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u503c\u5f97\u6ce8\u610f\u7684\u662f \u6839\u636e\u6587\u6863\u4e2d\u914d\u7f6e network_info_plus \u83b7\u53d6wifi\u7684\u540d\u79f0\u8fd4\u56de\u7684\u662f null, \u539f\u56e0\u662f\u9700\u8981\u83b7\u53d6\u5b89\u5353\u7684\u6743\u9650,\u8fd8\u9700\u8981\u901a\u8fc7\u83b7\u53d6\u5e94\u7528\u7684\u5b9a\u4f4d\u4fe1\u606f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b2c\u4e00\u6b65\u914d\u7f6e\u5b89\u5353\u6743\u9650<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 android\/app\/src\/main\/AndroidMainifest.xml \u4e2d\u914d\u7f6e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- \u83b7\u53d6WIFI\u4fe1\u606f --&gt;<br>&lt;uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\" \/&gt;<br>&lt;uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\" \/&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 android\/app\/build.gradle \u6587\u4ef6\u4e2d\u6dfb\u52a0<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> &nbsp; &nbsp;defaultConfig {<br> &nbsp; &nbsp; &nbsp; &nbsp;...<br> &nbsp; &nbsp; &nbsp; &nbsp;ndk {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'<br> &nbsp; &nbsp; &nbsp;  }<br> &nbsp;  }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528 \u5728\u7ec4\u4ef6\u4e2d\u7684 onInit \u5468\u671f\u4e2d\u4f7f\u7528<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> &nbsp;@override<br> &nbsp;void onInit()async{<br> &nbsp; &nbsp;super.onInit();<br> &nbsp; &nbsp;\/\/ \u76d1\u542c\u7f51\u7edc\u53d8\u5316<br> &nbsp; &nbsp;await checkLocationPermission();<br> &nbsp; &nbsp;final connectivity = Connectivity();<br> &nbsp; &nbsp;connectivity.onConnectivityChanged.listen((event) async {<br> &nbsp; &nbsp; &nbsp;if (event == ConnectivityResult.wifi) {<br> &nbsp; &nbsp; &nbsp; &nbsp;await checkLocationPermission();<br> &nbsp; &nbsp;  }<br> &nbsp;  });<br>  }<br>\/*\u6388\u6743\u83b7\u53d6\u4f4d\u7f6e\u6743\u9650\u7528\u4e8e\u83b7\u53d6\u65e0\u7ebf\u540d\u79f0 *\/<br> &nbsp;checkLocationPermission()async{<br> &nbsp; &nbsp;LocationPermission permission = await Geolocator.checkPermission();<br> &nbsp; &nbsp;if (permission == LocationPermission.denied) {<br> &nbsp; &nbsp; &nbsp;permission = await Geolocator.requestPermission();<br> &nbsp; &nbsp; &nbsp;if (permission == LocationPermission.denied) {<br> &nbsp; &nbsp; &nbsp; &nbsp;print('\u4f4d\u7f6e\u6388\u6743\u88ab\u62d2\u4e86');<br> &nbsp; &nbsp;  }<br> &nbsp;  }<br> &nbsp; &nbsp;if (permission == LocationPermission.deniedForever) {<br> &nbsp; &nbsp; &nbsp;print(\"\u4f4d\u7f6e\u6388\u6743\u88ab\u6c38\u4e45\u62d2\u4e86\");<br> &nbsp;  }<br> &nbsp; &nbsp;\/\/ \u6388\u6743\u901a\u8fc7<br> &nbsp; &nbsp;getCurrentWifiName();<br>  }<br>\/**\u83b7\u53d6\u5f53\u524d\u65e0\u7ebf\u540d\u79f0 *\/<br> &nbsp;getCurrentWifiName() async {<br> &nbsp; &nbsp;final info = NetworkInfo();<br> &nbsp; &nbsp;final getWifiName = await info.getWifiName();<br> &nbsp; &nbsp;var formatWifiName = getWifiName?.replaceAll('\"','');<br> &nbsp; &nbsp;wifiName.value = formatWifiName??'\u8bf7\u68c0\u67e5\u7f51\u7edc\u8fde\u63a5';<br> &nbsp; &nbsp;update();<br>  }<br>\u200b<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528\u7b2c\u4e09\u65b9\u63d2\u4ef6 connectivity_plus \u7528\u6765\u76d1\u542c\u5207\u6362\u7f51\u7edc\u7684\u53d8\u5316 network_info_plus [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[63],"tags":[],"class_list":["post-667","post","type-post","status-publish","format-standard","hentry","category-flutter"],"_links":{"self":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/667","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=667"}],"version-history":[{"count":1,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/667\/revisions"}],"predecessor-version":[{"id":668,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/667\/revisions\/668"}],"wp:attachment":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=667"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=667"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}