How to set USB Tethering automatically when plugged in (Android 8.1)

1.2k Views Asked by At

I'm going to create a background service (or whatever else) to enable USB tethering to share 4G internet on my pc automatically when the phone is plugged in.

I have an OP5 (Android 8.1) with root.

I tried Automate app, but it doesn't work (getting an exception when the task try to enable tether USB)

I tried to call setUsbTethering by reflection, I got an InvocationTargetException due to MANAGE_USB permission, I tried to grant this permission, but it seems that require to enumerate devices and when I try to get devices using getDeviceList the result is empty.

The last thing, after some research some people did the trick by shell command like

service call connectivity CODE i32 1

but the code seems to be different according to version (30, 32 or 33) from the internal AIDL file.

So, I finally decided to ask for some help since I don't have any pieces of knowledge about Android core and advanced things, any suggestion or help to achieve this will be appreciated.

0

There are 0 best solutions below