public boolean disableDataConnectivity() {
   enforceModifyPermission();
   ConnectivityManager cm =
       (ConnectivityManager) mApp.mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
   cm.setMobileDataEnabled(false);
   return true;
 }
 public void setPreferedNetworkType(int networkType, Message response) {
   Log.d(LOG_TAG, "Mobile Dataconnection is online setting it down");
   mDesiredNetworkType = networkType;
   mNetworktypeResponse = response;
   ConnectivityManager cm =
       (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
   // start listening for the connectivity change broadcast
   startListening();
   cm.setMobileDataEnabled(false);
 }
    @Override
    public void handleMessage(Message msg) {
      switch (msg.what) {
          // networktype was set, now we can enable the dataconnection again
        case MESSAGE_SET_PREFERRED_NETWORK_TYPE:
          ConnectivityManager cm =
              (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);

          Log.d(LOG_TAG, "preferred NetworkType set upping Mobile Dataconnection");
          cm.setMobileDataEnabled(true);
          // everything done now call back that we have set the networktype
          AsyncResult.forMessage(mNetworktypeResponse, null, null);
          mNetworktypeResponse.sendToTarget();
          mNetworktypeResponse = null;
          break;
        default:
          throw new RuntimeException("unexpected event not handled");
      }
    }
Exemplo n.º 4
0
 private void setMobileDataEnabled(boolean on) {
   mDataEnabled = on;
   ConnectivityManager cm =
       (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
   cm.setMobileDataEnabled(on);
 }