android - 通过热点传输文件
问题描述
通过热点传输文件
该项目通过wifi将文件传输到PC。
我想通过wifi和热点发送文件。
这与 wifi IP 共享文件。
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.os.Parcelable;
import com.hwangjr.rxbus.RxBus;
import me.pengtao.filetransfer.Constants;
public class WifiConnectChangedReceiver extends
BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(intent.getAction())) {
Parcelable parcelableExtra = intent
.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if (null != parcelableExtra) {
NetworkInfo networkInfo = (NetworkInfo) parcelableExtra;
RxBus.get().post(Constants.RxBusEvent
Type.WIFI_CONNECT_CHANGE_EVENT,
networkInfo.getState());
}
}
}
}
此代码用于获取 wifi 的 IP 地址。我想通过wifi和热点共享文件。因此,我替换了此代码以获取 wifi 和热点 IP。
public void getDeviceIpAddress() {
try {
for (Enumeration<NetworkInterface> enumeration = NetworkInterface
.getNetworkInterfaces(); enumeration.hasMoreElements();) {
NetworkInterface networkInterface = enumeration.nextElement();
for (Enumeration<InetAddress> enumerationIpAddr = networkInterface
.getInetAddresses(); enumerationIpAddr
.hasMoreElements();) {
InetAddress inetAddress = enumerationIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()
&& inetAddress.getAddress().length == 4) {
tvServerIP.setText(inetAddress.getHostAddress());
}
}
}
} catch (SocketException e) {
Log.e("ERROR:", e.toString());
}
}
我尝试使用此代码,但没有成功。
我怎样才能做到这一点?
解决方案
推荐阅读
- android - 使用 withContext 与 suspendCoroutine 运行协程函数
- python - 使用 python 发送 html gmail 时不显示文本
- react-native - 如何在子组件中使用父回调?
- c++ - 使用 clang 编译 .cl 内核文件
- jquery - 隐藏第一个项目并显示第一个带有循环的隐藏项目
- c++ - 使用可变参数模板对重载方法进行自动参数转发
- jquery - 单击操作后存在具有特定类的计数元素
- java - 有没有办法将包含图片的卡片视图分享给其他社交应用程序?
- java - 有没有办法从 Cucumber Report 中的内部代码打印值?
- compression - 如何解压缩存储在使用 zstd 压缩的 HDF5 文件中的数据?