{"id":578,"date":"2020-06-20T14:39:24","date_gmt":"2020-06-20T06:39:24","guid":{"rendered":"https:\/\/badgameshow.com\/fly\/?p=578"},"modified":"2020-07-07T11:56:12","modified_gmt":"2020-07-07T03:56:12","slug":"github-%e5%a5%bd%e7%94%a8%e5%88%86%e4%ba%abwifiutilswifi%e5%b7%a5%e5%85%b7","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/fly\/github-%e5%a5%bd%e7%94%a8%e5%88%86%e4%ba%abwifiutilswifi%e5%b7%a5%e5%85%b7\/","title":{"rendered":"Github \u597d\u7528\u5206\u4eabWifiUtils(Wifi\u5de5\u5177)"},"content":{"rendered":"<h3>1.\u5148\u5c0e\u5165\u51fd\u793a\u5eab(build.gradle: Module)<\/h3>\n<pre><code class=\"language-Gradle line-numbers\">dependencies {\n    implementation 'com.thanosfisherman.wifiutils:wifiutils:1.6.1'\n}\n<\/code><\/pre>\n<h3>2.\u6dfb\u52a0\u6b0a\u9650<\/h3>\n<pre><code class=\"language-XML line-numbers\">&lt;uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"\/&gt;\n&lt;uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"\/&gt;\n&lt;uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"\/&gt;\n<\/code><\/pre>\n<h3>3.\u7a0b\u5f0f\u78bc\u7bc4\u4f8b<\/h3>\n<h4>a.\u8a62\u554f\u6b0a\u9650<\/h4>\n<pre><code class=\"language-Kotlin line-numbers\">ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), 666)\n<\/code><\/pre>\n<h4>b.\u958b\u555fWifi<\/h4>\n<pre><code class=\"language-Kotlin line-numbers\">WifiUtils.withContext(applicationContext).enableWifi()\n<\/code><\/pre>\n<h4>c.\u95dc\u9589Wifi<\/h4>\n<pre><code class=\"language-Kotlin line-numbers\">WifiUtils.withContext(applicationContext).disableWifi()\n<\/code><\/pre>\n<h4>d.\u9023\u7ddaWifi<\/h4>\n<pre><code class=\"language-Kotlin line-numbers\">WifiUtils.withContext(applicationContext)\n    .connectWith(\"SSID\", \"PASSWORD\")\n    .setTimeout(15000)\n    .onConnectionResult(object : ConnectionSuccessListener {\n        override fun failed(errorCode: ConnectionErrorCode) {\n              Log.d(\"WifiUtils\", errorCode.toString())\n        }\n\n        override fun success() {\n              Log.d(\"WifiUtils\", \"success\")\n        }\n     }).start()\n<\/code><\/pre>\n<h4>e.\u79fb\u9664\u9023\u7ddaWifi<\/h4>\n<pre><code class=\"language-Kotlin line-numbers\">WifiUtils.withContext(applicationContext)\n     .remove(\"SSID\", object : RemoveSuccessListener {\n           override fun failed(errorCode: RemoveErrorCode) {\n               Log.d(\"WifiUtils\", errorCode.toString())\n           }\n\n           override fun success() {\n               Log.d(\"WifiUtils\", \"success\")\n           }\n     })\n<\/code><\/pre>\n<h3>4.\u6548\u679c\u5c55\u793a<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/badgameshow.com\/fly\/wp-content\/uploads\/2020\/06\/WifiUtils.gif\" alt=\"\" \/><\/p>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>1.\u5148\u5c0e\u5165\u51fd\u793a\u5eab(build.gradle: Module) dependencies { implement &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[57],"tags":[56,15,89],"class_list":["post-578","post","type-post","status-publish","format-standard","hentry","category-github","tag-github","tag-kotlin","tag-wifiutils"],"_links":{"self":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/578","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/comments?post=578"}],"version-history":[{"count":2,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/578\/revisions"}],"predecessor-version":[{"id":582,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/posts\/578\/revisions\/582"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/media?parent=578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/categories?post=578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/fly\/wp-json\/wp\/v2\/tags?post=578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}