App Check Network

Source: Internet
Author: User
<span id="Label3"></p><p><p></p></p> <p><p>Permissions:</p></p> <pre class="prettyprint"><pre class="prettyprint"><span style="COLOR: rgb(0,0,0)"> </span> <span style="COLOR: rgb(0,0,136)"></span><uses-permission<span style="COLOR: rgb(0,0,0)"></span><span style="COLOR: rgb(136,34,136)">android:name</span><span style="COLOR: rgb(102,102,0)">=</span><span style="COLOR: rgb(136,0,0)">"android.permission.INTERNET" </span><span style="COLOR: rgb(0,0,0)"> </span> <span style="COLOR: rgb(0,0,136)"></span><span style="COLOR: rgb(136,34,136)"></span> <span style="COLOR: rgb(0,0,136)"></span> /> <uses-permission<span style="COLOR: rgb(0,0,0)"></span>android:name = <span style="COLOR: rgb(0,0,0)"></span> <span style="COLOR: rgb(102,102,0)"> </span> <span style="COLOR: rgb(136,0,0)">"android.permission.ACCESS_NETWORK_STATE"</span><span style="COLOR: rgb(0,0,0)"></span><span style="COLOR: rgb(0,0,136)">/></span></pre></pre> <p><p></p></p> <p><p>Used to determine and turn on network settings<br>public class Netcheckwebserver {<br>Public Netcheckwebserver () {<br>}</p></p> <p>public static Boolean NetworkStatus (context Context) {<br>Boolean flag;<br>Networkinfo networkinfo;<br>Networkinfo networkinfo1;<br>Flag = true;<br>Connectivitymanager Connectivitymanager = (connectivitymanager) Context.getsystemservice (Context.CONNECTIVITY_ SERVICE);<br>Networkinfo = Connectivitymanager.getnetworkinfo (connectivitymanager.type_mobile);<br>Networkinfo1 = Connectivitymanager.getnetworkinfo (connectivitymanager.type_wifi);<br>if (networkinfo = = NULL | |!networkinfo.isconnectedorconnecting ()) && (NETWORKINFO1 = = NULL | |! Networkinfo1.isconnectedorconnecting ())) {<br>Opennetworksettings (context);<br>Flag = false;<br>}<br>Return flag;<br>}<br>Jump to Settings interface, manually modify network status<br>private static void Opennetworksettings (final context Context) {<br>(new Android.app.AlertDialog.Builder (context))<br>. settitle ("network Service not Found")<br>. setmessage ("whether to turn on network Services")<br>. Setpositivebutton ("ok",<br>New Android.content.DialogInterface.OnClickListener () {</p> <p><p>public void OnClick (<br>Dialoginterface dialoginterface, int I) {</p></p> <p>Mobile system version greater than 10 is 3.0 or later<br>If (Integer<br>. parseint (android.os.Build.VERSION.SDK) > 10) {<br>Intent Intent = new Intent (<br>"android.settings.WIRELESS_SETTINGS");<br>Context.startactivity (intent);<br>} else {<br>Intent intent1 = new Intent ("/");<br>Intent1.setcomponent (new ComponentName (<br>"com.android.settings",<br>"com.android.settings.WirelessSettings"));<br>Intent1.setaction ("android.intent.action.VIEW");<br>Context.startactivity (intent1);<br>Dialoginterface.cancel ();<br>}<br>}<br>})<br>. Setnegativebutton ("cancel",<br>New Android.content.DialogInterface.OnClickListener () {<br>public void OnClick (<br>Dialoginterface dialoginterface, int I) {<br>Dialoginterface.dismiss ();<br>}<br>}). Show ();<br>}<br>}<br></p><p><p>App Check Network</p></p></span>

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.