次の問題を解決したい。私のデバイスは AP モード (ポータブル WiFi ホットスポット) です。It has to show IP of it
. 別のデバイスが、既知の IP を使用してこのデバイスに接続します。WiFi ルーターを使用せずに、デバイス間で動作する必要があります。無線がすでに AP モードで動作している場合、IP アドレスを取得する方法は? APに関するコードがいくつかあります:
public boolean setWifiApEnabled(WifiConfiguration config, boolean enabled) {
try {
if (enabled) { // disable WiFi in any case
mWifiManager.setWifiEnabled(false);
}
Method method = mWifiManager.getClass().getMethod(
"setWifiApEnabled", WifiConfiguration.class,
boolean.class);
return (Boolean) method.invoke(mWifiManager, config, enabled);
} catch (Exception e) {
//Log.e(TAG, "", e);
return false;
}
}
public int getWifiApState() {
try {
Method method = mWifiManager.getClass().getMethod(
"getWifiApState");
return (Integer) method.invoke(mWifiManager);
} catch (Exception e) {
//Log.e(TAG, "", e);
return WIFI_AP_STATE_FAILED;
}
}
public static boolean IsWifiApEnabled(Context context){
boolean isWifiAPEnabled = false;
WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
Method[] wmMethods = wifi.getClass().getDeclaredMethods();
for(Method method: wmMethods){
if(method.getName().equals("isWifiApEnabled")) {
try {
isWifiAPEnabled = (Boolean) method.invoke(wifi);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
return isWifiAPEnabled;
}
}
多分それのIPを取得するためのいくつかのトリックがありますか? 私を助けてください。ありがとう。