App Check Network
Last Update:2015-07-22
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>