Gilles Quénot
Gilles Quénot

Reputation: 185025

Can i enable USB tethering with SL4A?

I have had searched in API reference for a class/method to enable USB tethering, but found none. I wonder if it's still possible.

For information, I use a rooted HTC Wildfire with Cyanogenmod 7 and Android 2.3.7.

If it's not possible, I'm interested for a Java sample code to do it.

Upvotes: 1

Views: 880

Answers (2)

Vi.
Vi.

Reputation: 38694

If you have root enabled, you by just try to do it whithoug SL4A or Android. I use this script:

#!/system/bin/sh
iptables -D droidwall-3g -m owner --uid-owner 0 -j RETURN
iptables -I droidwall-3g -m owner --uid-owner 0 -j RETURN
iptables -t nat -D POSTROUTING -o rmnet0 -j MASQUERADE
iptables -t nat -I POSTROUTING -o rmnet0 -j MASQUERADE
echo 1 > /sys/class/usb_composite/rndis/enable
ifconfig usb0 192.168.42.129 up
echo 1 > /proc/sys/net/ipv4/conf/usb0/forwarding
echo 1 > /proc/sys/net/ipv4/conf/rmnet0/forwarding

Maybe for other devices (mine is SE Xperia X10) you need to adjust things like /sys/class/usb_composite/rndis/enable.

Upvotes: 1

Grace B
Grace B

Reputation: 1406

Not using the built in APIs (as you've checked), which simply means no, not if you're not willing to do a bit of work.

If, however, you are using Beanshell, JRuby or Rhino, then as per the SL4A FAQ ("API bridge?" question), "you can invoke Java calls directly" suggesting to "See the documentation for those interpreters" for how to do so (though I couldn't find it). However on the Unofficial Releases page, it states that:

"Beanshell and Rhino can both directly access the android api. However, many Android api calls required a context, which, due to the way they are run, these interpreters don't have. A solution is being sought... suggestions appreciated."

And as per this answer, I believe a Context is required, though I may be wrong.

Finally, your last option would be to clone the source code for whatever interpreter you're using and add the call(s) your require. Quoting the FAQ again; "The RPC layer is easy to extend." and there's even a little walkthrough for it.

Good luck!

Upvotes: 1

Related Questions