usb tethering

pappicio

Active Member
Licensed User
Longtime User
hi all, is possible to translate this java code into readeable b4a code?

B4X:
public int setUsbTethering(boolean enable) 
   {   
      final android.net.IConnectivityManager mService;
          try {
              return mService.setUsbTethering(enable);
          } 
          catch (RemoteException e) 
          {      
              return 2;
          }
   }
}

thanks a lot.
 

pappicio

Active Member
Licensed User
Longtime User
This code will not work. mService is null. Where did you see it?

on internet, on a forum tolking about it... I don't remember where exactly.... (maybe forgot to paste something....)
btw thanks.
if I'll have more code on it, I'll post.
 
Upvote 0

Aleksandr

Member
Licensed User
Longtime User
is possible to translate this java code into readeable b4a code?

B4X:
mUsbTether = (CheckBoxPreference) findPreference(USB_TETHER_SETTINGS);

    private void setUsbTethering(boolean enabled) {
        ConnectivityManager cm =
            (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
        mUsbTether.setChecked(false);
        if (cm.setUsbTethering(enabled) != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
            mUsbTether.setSummary(R.string.usb_tethering_errored_subtext);
            return;
        }
        mUsbTether.setSummary("");
    }
Source: https://github.com/android/platform.../src/com/android/settings/TetherSettings.java
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Try this (GetContext is available in the JavaObject tutorial thread):
B4X:
Dim cm As JavaObject = GetContext.RunMethod("getSystemService", Array("connectivity"))
Log(cm.RunMethod("setUsbTethering", Array(True))

You also need to add the android.permission.CHANGE_NETWORK_STATE with the manifest editor.

The return values:
SS-2014-08-20_08.07.00.png
 
Upvote 0
Top