私はアンドロイド(OS_VERSION 4.0)デバイスを持っています。Wi-Fi ネットワークを介して別の Android デバイスとファイルを共有したいと考えています。これは、上記の Android 4.0 で wifi p2p(WifiDirect) を介して実行できます。ただし、これは Android 2.3.3 デバイス (Android 4.0 より前) では不可能です。Superbeam アプリケーションは、Android 2.3.3 で共有ネットワークを介してファイル共有を行うことがわかりました。このアプリケーションは、デバイスのインターネット接続を共有することなく、wifi テザリングを作成します。作成されたテザリングは、インターネットを共有するためではなく、ファイルを共有するためにのみ使用されます。このコンセプトを実現する方法。誰でも私を助けることができますか?
1929 次
1 に答える
1
この回答は、同じ質問をしている誰かに役立つかもしれません。私が実装した簡単なロジックは、
1.wifiテザリング(ホットスポット)の作成
2.モバイルデータ接続を無効にする
コードは、
//To enable the wifi hotspot
setWifiTetheringEnabled(true);
//To disable the mobile data cnnection
setMobileDataEnabled(false);
private void setWifiTetheringEnabled(boolean enable) {
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
Method[] methods = wifiManager.getClass().getDeclaredMethods();
for (Method method : methods) {
if (method.getName().equals("setWifiApEnabled")) {
try {
method.invoke(wifiManager, null, enable);
} catch (Exception ex) {
}
break;
}
}
}
private void setMobileDataEnabled(Context context, boolean enabled) {
try {
final ConnectivityManager conman = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
final Class conmanClass = Class
.forName(conman.getClass().getName());
final Field iConnectivityManagerField = conmanClass
.getDeclaredField("mService");
iConnectivityManagerField.setAccessible(true);
final Object iConnectivityManager = iConnectivityManagerField
.get(conman);
final Class iConnectivityManagerClass = Class
.forName(iConnectivityManager.getClass().getName());
final Method setMobileDataEnabledMethod = iConnectivityManagerClass
.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
setMobileDataEnabledMethod.setAccessible(true);
setMobileDataEnabledMethod.invoke(iConnectivityManager, enabled);
} catch (ClassNotFoundException | NoSuchFieldException
| IllegalAccessException | IllegalArgumentException
| NoSuchMethodException | InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
于 2014-12-15T12:16:20.773 に答える