Android to determine the current network status and jump to the settings interface

Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="font-size: 18px;"><strong><span style="color: #ff9900;">today, want to do this jump to the network settings interface,<em><code class="java spaces"> 刚开始用</code></em></span></strong></span></p></p><p><p><span style="font-size: 18px; color: #00ff00;"><strong><em><code class="java plain">intent = </code><code class="java keyword">new</code><code class="java plain">Intent(<span style="color: #993366;">Settings.ACTION_WIRELESS_SETTINGS</span>);</code></em></strong></span></p></p><p><p><span style="font-size: 18px;"><strong><span style="color: #ff9900;">behold, always appear settings. Wirelesssettings can not find (just can't hint out, show red shading), I later checked the information, the results found that with the version, my is Android 4.3, so need to use</span></strong></span></p></p><em><em><span style="color: #0000ff;"><code class="java spaces">                       <span style="font-size: 16px;"> </span></code><span style="font-size: 16px;"><code class="java plain">intent = </code><code class="java keyword">new</code> <code class="java plain">Intent(<span style="color: #993366;">android.provider.Settings.ACTION_WIRELESS_SETTINGS</span>);</code></span></span></em></em><p><p></p></p><p><p><code class="java plain"> </code></p></p><p><p></p></p> <table border="0" cellspacing="0" cellpadding="0"> <tbody> <tr> <td class="gutter">123456789101112131415161718192021222324252627282930313233343536373839404142</td> <td class="code"><code class="java comments"><code class="java comments">// 加权限<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE">  </code></code><code class="java spaces"><code class="java spaces">  </code></code><code class="java comments"><code class="java comments">/*</code></code><code class="java spaces"><code class="java spaces"> </code></code><code class="java comments"><code class="java comments">* 判断网络连接是否已开</code></code><code class="java spaces"><code class="java spaces"> </code></code><code class="java comments"><code class="java comments">* true 已打开  false 未打开</code></code><code class="java spaces"><code class="java spaces"> </code></code><code class="java comments"><code class="java comments">* */</code></code><code class="java keyword"><code class="java keyword">public</code></code> <code class="java keyword"><code class="java keyword">static</code></code> <code class="java keyword"><code class="java keyword">boolean</code></code> <code class="java plain"><code class="java plain">isConn(Context context){</code></code><code class="java spaces"><code class="java spaces">    </code></code><code class="java keyword"><code class="java keyword">boolean</code></code> <code class="java plain"><code class="java plain">bisConnFlag=</code></code><code class="java keyword"><code class="java keyword">false</code></code><code class="java plain"><code class="java plain">;</code></code><code class="java spaces"><code class="java spaces">    </code></code><code class="java plain"><code class="java plain">ConnectivityManager conManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);</code></code><code class="java spaces"><code class="java spaces">    </code></code><code class="java plain"><code class="java plain">NetworkInfo network = conManager.getActiveNetworkInfo();</code></code><code class="java spaces"><code class="java spaces">    </code></code><code class="java keyword"><code class="java keyword">if</code></code><code class="java plain"><code class="java plain">(network!=</code></code><code class="java keyword"><code class="java keyword">null</code></code><code class="java plain"><code class="java plain">){</code></code><code class="java spaces"><code class="java spaces">        </code></code><code class="java plain"><code class="java plain">bisConnFlag=conManager.getActiveNetworkInfo().isAvailable();</code></code><code class="java spaces"><code class="java spaces">    </code></code><code class="java plain"><code class="java plain">}</code></code><code class="java spaces"><code class="java spaces">    </code></code><code class="java keyword"><code class="java keyword">return</code></code> <code class="java plain"><code class="java plain">bisConnFlag;</code></code><code class="java plain"><code class="java plain">}</code></code><code class="java preprocessor"><code class="java preprocessor">/**</code></code><code class="java spaces"><code class="java spaces"> </code></code><code class="java preprocessor"><code class="java preprocessor">* 当判断当前手机没有网络时选择是否打开网络设置</code></code><code class="java spaces"><code class="java spaces"> </code></code><code class="java preprocessor"><code class="java preprocessor">* @param context</code></code><code class="java spaces"><code class="java spaces"> </code></code><code class="java preprocessor"><code class="java preprocessor">*/</code></code><code class="java keyword"><code class="java keyword">public</code></code> <code class="java keyword"><code class="java keyword">static</code></code> <code class="java keyword"><code class="java keyword">void</code></code> <code class="java plain"><code class="java plain">showNoNetWorkDlg(</code></code><code class="java keyword"><code class="java keyword">final</code></code> <code class="java plain"><code class="java plain">Context context) {</code></code><code class="java spaces"><code class="java spaces">    </code></code><code class="java plain"><code class="java plain">AlertDialog.Builder builder = </code></code><code class="java keyword"><code class="java keyword">new</code></code> <code class="java plain"><code class="java plain">Builder(context);</code></code><code class="java spaces"><code class="java spaces">    </code></code><code class="java plain"><code class="java plain">builder.setIcon(R.drawable.ic_launcher)         </code></code><code class="java comments"><code class="java comments">//</code></code><code class="java spaces"><code class="java spaces">            </code></code><code class="java plain"><code class="java plain">.setTitle(R.string.app_name)            </code></code><code class="java comments"><code class="java comments">//</code></code><code class="java spaces"><code class="java spaces">            </code></code><code class="java plain"><code class="java plain">.setMessage(</code></code><code class="java string"><code class="java string">"当前无网络"</code></code><code class="java plain"><code class="java plain">).setPositiveButton(</code></code><code class="java string"><code class="java string">"设置"</code></code><code class="java plain"><code class="java plain">, </code></code><code class="java keyword"><code class="java keyword">new</code></code> <code class="java plain"><code class="java plain">OnClickListener() {</code></code><code class="java spaces"><code class="java spaces">                </code></code><code class="java spaces"><code class="java spaces">                </code></code><code class="java color1"><code class="java color1">@Override</code></code><code class="java spaces"><code class="java spaces">                </code></code><code class="java keyword"><code class="java keyword">public</code></code> <code class="java keyword"><code class="java keyword">void</code></code> <code class="java plain"><code class="java plain">onClick(DialogInterface dialog, </code></code><code class="java keyword"><code class="java keyword">int</code></code> <code class="java plain"><code class="java plain">which) {</code></code><code class="java spaces"><code class="java spaces">                    </code></code><code class="java comments"><code class="java comments">// 跳转到系统的网络设置界面</code></code><code class="java spaces"><code class="java spaces">                    </code></code><code class="java plain"><code class="java plain">Intent intent = </code></code><code class="java keyword"><code class="java keyword">null</code></code><code class="java plain"><code class="java plain">;</code></code><code class="java spaces"><code class="java spaces">                    </code></code><code class="java comments"><code class="java comments">// 先判断当前系统版本</code></code><code class="java spaces"><code class="java spaces">                    </code></code><code class="java keyword"><code class="java keyword">if</code></code><code class="java plain"><code class="java plain">(android.os.Build.VERSION.SDK_INT > </code></code><code class="java value"><code class="java value">10</code></code><code class="java plain"><code class="java plain">){  </code></code><code class="java comments"><code class="java comments">// 3.0以上</code></code><code class="java spaces"><code class="java spaces">                        </code></code><code class="java plain"><code class="java plain">intent = </code></code><code class="java keyword"><code class="java keyword">new</code></code> <code class="java plain"><code class="java plain">Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);</code></code><code class="java spaces"><code class="java spaces">                    </code></code><code class="java plain"><code class="java plain">}</code></code><code class="java keyword"><code class="java keyword">else</code></code><code class="java plain"><code class="java plain">{</code></code><code class="java spaces"><code class="java spaces">                        </code></code><code class="java plain"><code class="java plain">intent = </code></code><code class="java keyword"><code class="java keyword">new</code></code> <code class="java plain"><code class="java plain">Intent();</code></code><code class="java spaces"><code class="java spaces">                        </code></code><code class="java plain"><code class="java plain">intent.setClassName(</code></code><code class="java string"><code class="java string">"com.android.settings"</code></code><code class="java plain"><code class="java plain">, </code></code><code class="java string"><code class="java string">"com.android.settings.WirelessSettings"</code></code><code class="java plain"><code class="java plain">);</code></code><code class="java spaces"><code class="java spaces">                    </code></code><code class="java plain"><code class="java plain">}</code></code><code class="java spaces"><code class="java spaces">                    </code></code><code class="java plain"><code class="java plain">context.startActivity(intent);</code></code><code class="java spaces"><code class="java spaces">                    </code></code><code class="java spaces"><code class="java spaces">                </code></code><code class="java plain"><code class="java plain">}</code></code><code class="java spaces"><code class="java spaces">            </code></code><code class="java plain"><code class="java plain">}).setNegativeButton(</code></code><code class="java string"><code class="java string">"知道了"</code></code><code class="java plain"><code class="java plain">, </code></code><code class="java keyword"><code class="java keyword">null</code></code><code class="java plain"><code class="java plain">).show();</code></code><code class="java plain"><code class="java plain">}</uses-permission></code></code></td> </tr> </tbody> </table><p><p>Android to determine the current network status and jump to the settings interface</p></p></span>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.