Я использую этот код Java
ConnectivityManager connectivityManager = ((ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE));
try {
Method method = connectivityManager.getClass().getDeclaredMethod("getTetherableIfaces");
String[] strings = ((String[]) method.invoke(connectivityManager));
Log.i("hotspot", "getIface: "+strings.toString());
Method methodTether = connectivityManager.getClass().getDeclaredMethod("tether",String.class);
methodTether.setAccessible(true);
String[] param =new String[]{"wlan0"};
int i = (int) method.invoke(connectivityManager,"wlan0");
Log.i(TAG, "getIface: "+ "errorcode"+ i);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
, но я получаю эту ошибку
java.lang.IllegalArgumentException: Wrong number of arguments; expected 0, got 1
at java.lang.reflect.Method.invoke(Native Method)
И это функция привязки, которую я пытаюсь вызвать.
public int tether(String iface) {
try {
return mService.tether(iface);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
Я пытался вызвать метод с помощью object[]{"wlan0"}, String[]{"wlan0"}, (object){"wlan0"}, {"wlan0"}
и (Object[])String[]{"wlan0"}
, но получаю ту же ошибку.Я не могу понять, что я делаю неправильно.За любую помощь буду благодарен.