Wednesday, April 23, 2014

android judgment networking, always error? Online, urgent! !


been an error, the error in the init () method in solving Thank you! ! !
public class MainActivity extends Activity {

private TextView text;

/ ** Called when the activity is first created. * /
@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.main);

init ();
}

/ **
* Initialize achieve
* /
private void init () {
text = (TextView) findViewById (R.id.waytext);
/ / Get the system-level network administrators object
ConnectivityManager manager = (ConnectivityManager) this / / this line this is correct
. GetSystemService (CONNECTIVITY_SERVICE);
NetworkInfo info = manager.getActiveNetworkInfo ();
if (info == null) under {/ / no network situation
/ / Go to the Network Settings page
startActivity (new Intent (android.provider.Settings.ACTION_SETTINGS));
Under} else {/ / have net case
if (info.isAvailable ()) {/ / network available
/ ** Is the phone comes with networking * /
if (info.getType () == ConnectivityManager.TYPE_MOBILE) {
if (info.getState () == State.CONNECTED) {
text.setText (String.valueOf ("mobile phone network is available and connected" + "\ n"
+ "Network connection method is: \ n" + info.getType () + ", MOBILE"));
}

/ ** WIFI networking * /
} Else {
text.setText (String.valueOf ("network connection mode is:" + info.getType ()
+ ", WI-FI"));
startActivity (new Intent (
android.provider.Settings.ACTION_WIFI_SETTINGS));
}
} Else {
text.setText (String.valueOf ("mobile phone network is not available"));
}

}
}
}
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
That this should be no problem, you look at the logcat log, which line the error
Reply:
See if it is less privileges

Reply:
Not set permissions in the manifest, I was just watching to the log, thank you

No comments:

Post a Comment