简体   繁体   中英

How to activate suspended 3G connection in android

If you access the browser by disabling 3G (clicking F8) , still browser works without any issues. I want similar type of functionality in my app , how can I implement same in my app.

Currently we are using following code in our app:

protected boolean isNetworkCoverageAvailable()
{
   boolean result = false;
  Context oContext = AndroidContext.getContext();
  ConnectivityManager connMgr = (ConnectivityManager) oContext.getSystemService(Context.CONNECTIVITY_SERVICE);
   NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
   NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

   if(wifi.isConnected() == true){
       result = true;
   } else if (mobile.isConnectedOrConnecting() == true){
       result = true;
   } else {
       result = oMgr.getDataState() == TelephonyManager.DATA_CONNECTED;
   }
   Log.d(TAG, "Result: " + result + "");
   return result;
}

The app is working for Wi-Fi and 3G enabled , but I want app needs to activate 3G automatically if 3G is suspended because of unusuability of device.

How can I do this in Android ?

I don't think you can enable 3G programmatically. The user chooses to disable or enable it.

What you can do is ask the user to enable WIFI or 3G and direct them to the settings screen? I think I have seen apps do this before.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM