Saturday, February 2, 2013

Android Invoking intents for different purposes like wifi/mobile operator/Location based services etc

1) For WI-FI connection

startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));

2) For network operator settings


Intent intent=new Intent(Settings.ACTION_NETWORK_OPERATOR_SETTINGS);

ComponentName cName = new ComponentName("com.android.phone","com.android.phone.Settings");

intent.setComponent(cName);

 3) for location based services


Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);

there are more several settings which we can show at need during a successful run of an application.

beside this i have a function which can help you all to get network presentation state


public boolean isOnline() {
   ConnectivityManager conMgr = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
   NetworkInfo netInfo = conMgr.getActiveNetworkInfo();

   if(netInfo == null || !netInfo.isConnected() || !netInfo.isAvailable()){
       Toast.makeText(this, "No Internet connection!", Toast.LENGTH_LONG).show();
       return false;
   }
return true;
}

1 comment: