我使用DefaultHttpClient和HttpGet来轮询来自服务器的数据.现在,假设用户在Wi-Fi网络中并离开了房间.因此手机会自动开始使用3G网络.是否有任何此类更改的回调,以及我应该如何处理此类更改.我应该再次开始轮询还是操作系统会注意适当地进行更改
这是cmd行
"C:\Progra~2\Android\android-sdk\tools\emulator.exe" -avd Touch -netspeed full -netdelay none -http-proxy localhost:3128 -debug-proxy
Run Code Online (Sandbox Code Playgroud)
当我尝试从模拟器打开google.com时,这里是控制台:
server name 'localhost' resolved to 127.0.0.1:3128
proxy_http_setup: creating http proxy service connecting to: localhost:3128
server name 'localhost' resolved to 127.0.0.1:3128
proxy_http_setup: creating HTTP Proxy Service Footer is (len=2):
'
'
http_service_connect: trying to connect to (null)
http_service_connect: using HTTP rewriter
tcp:(null)(880): connecting
tcp:(null)(880): connected to http proxy, sending header
tcp:(null)(880): sending 27 bytes:
>> 43 4f 4e 4e 45 43 54 20 28 6e 75 6c 6c 29 …Run Code Online (Sandbox Code Playgroud) 我开始使用Google的C2DM了.此过程的一部分涉及在注册发生时接收广播意图.在Google的官方C2DM文档中,示例代码在BrodcastReceiver的onReceive()方法中显示以下注释:
// Send the registration ID to the 3rd party site that is sending the messages.
// This should be done in a separate thread.
Run Code Online (Sandbox Code Playgroud)
但是,我读过的所有内容,包括BroadcastReceiver的文档,都表明从onReceive()启动一个线程几乎肯定会引起问题,因为一旦onReceive()返回,该过程很快就会被杀死.
有人可能犯了一个错误,我应该忽略关于使用单独线程的评论,但我猜他们说这是有原因的,即使它有误导性.
有没有理由在返回之前不能或不应该使用与onReceive()相同的线程中的网络?如果这样做有问题,那么即使在C2DM之外,处理必须是常见情况的正确方法是什么?开始服务?
multithreading android broadcastreceiver android-networking android-c2dm
如果范围内有两个具有相同SSID,安全类型和密码的wifi网络,是否有任何可用的ID来区分它们?有没有办法在Android中获取该ID?
我是一个相当新的Android开发人员.我注意到的一件事是,当我走近/星巴克店内时,我的Android设备显示以下内容:

题:
这是对这个问题的后续问题:
如何确定哪个网络接口适用于Android中的Wifi,3G,4G(LTE)和VPN?
我得到了网络接口和他们的名字,我需要显示他们的类型列表(VPN,Wifi,3G,4G,本地等).
如何通过界面名称了解每种类型?("本地","eth0"等......).我需要显示名称列表,我可以用它来识别每种类型.
我可以使用inetaddress类获取局域网中的所有设备IP地址.我需要做的是反向查找ip-address并在网络中找到设备名称,如:"Jimmie的Macbook"
我的代码块能够通过本地网络范围获取所有IP地址:
private ArrayList<String> scanSubNet(String subnet) {
ArrayList<String> hosts = new ArrayList<>();
InetAddress inetAddress;
for (int i = 1; i <= 255; i++) {
try {
inetAddress = InetAddress.getByName(subnet + String.valueOf(i));
if (inetAddress.isReachable(1000)) {
hosts.add(inetAddress.getHostName());
Log.d(TAG, InetAddress.getByAddress(inetAddress.getAddress()).getHostAddress());
Log.d(TAG, InetAddress.getByAddress(inetAddress.getAddress()).getCanonicalHostName());
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
return hosts;
}
Run Code Online (Sandbox Code Playgroud)
我称之为我的方法;
ArrayList<String> subnetList = scanSubNet("192.168.1.");ArrayList<String> subnetList = scanSubNet("192.168.1.");
Run Code Online (Sandbox Code Playgroud)
在Log.d(TAG,我试图用反向dns获取设备名称.但两行都给我输出为ip-address(非设备名称为字符串)
有没有机会成功呢?
此致,Onder.
我正在构建一个网络监视器应用程序 在这里,我已成功实现了Wifi或移动数据中的跟踪数据使用等所有内容,但我想知道哪些SIM连接到互联网并使用移动数据.
使用下面的代码我能够知道我的双卡手机是否连接到Wifi或移动数据.
public static String isInternetConnected (Context ctx) {
ConnectivityManager connectivityMgr = (ConnectivityManager) ctx
.getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo wifi = connectivityMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
NetworkInfo mobile = connectivityMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
// Check if wifi or mobile network is available or not. If any of them is
// available or connected then it will return true, otherwise false;
if (wifi != null) {
if (wifi.isConnected()) {
return "wifi";
}
}
if (mobile != null) {
if (mobile.isConnected()) {
return "mobile";
}
}
return "none";
}
Run Code Online (Sandbox Code Playgroud)
如何在双卡安卓手机中获取消耗移动数据的SIM索引或SIM卡操作员名称?
我已经搜查了很多,我看到了张贴在SO不一样的答案很多问题 …
android operating-system internet-connection android-networking dual-sim
我们一直在使用WifiManager隐藏API来启用Wifi网络共享并创建一个接入点.Android上的API 26现在的问题是标签@RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)已添加到setWifiApEnabled函数中,现在调用返回false并打印以下日志:
W/WifiManager:PACKAGE_NAME尝试调用setWifiApEnabled enabled = true
阅读新文档时,它表示该函数已弃用,并将在即将发布的版本中删除,而是ConnectivityManager#startTethering在调用者具有适当权限时使用,但此方法在没有TETHER_PRIVILEGED权限时也存在同样的问题.文档中提供的另一个选项是使用,LocalOnlyHotspot但这对项目没用,因为创建的热点没有Internet连接.
我还使用startSoftAp隐藏API中的函数进行了测试,但由于引发了以下异常,因此没有成功的结果:
WifiService:用户10164和当前进程都没有android.permission.NETWORK_STACK
是否有任何解决方法可以在较新的API上激活Wifi热点?我也搜索了Wifi网络共享的替代方案,但唯一可行的选择似乎是蓝牙网络共享,只有获得3G速度的缺点.还考虑了Wifi Aware和Wifi P2P,但这些都存在互联网连接不能在设备之间共享的问题.
有关如何处理此问题的任何建议?
我正在尝试下载json包含斯洛文尼亚字符的文件,在将json文件作为字符串下载时,我将获得如下json数据中指定的特殊字符
"send_mail": "Po?lji elektronsko sporocilo.",
"str_comments_likes": "Komentarji, v?ecki in mejniki",
Run Code Online (Sandbox Code Playgroud)
我正在使用的代码
URL url = new URL(f_url[0]);
URLConnection conection = url.openConnection();
conection.connect();
try {
InputStream input1 = new BufferedInputStream(url.openStream(), 300);
String myData = "";
BufferedReader r = new BufferedReader(new InputStreamReader(input1));
StringBuilder totalValue = new StringBuilder();
String line;
while ((line = r.readLine()) != null) {
totalValue.append(line).append('\n');
}
input1.close();
String value = totalValue.toString();
Log.v("To Check Problem from http paramers", value);
} catch (Exception e) {
Log.v("Exception Character Isssue", "" …Run Code Online (Sandbox Code Playgroud) android ×10
wifi ×2
android-c2dm ×1
android-wifi ×1
dns ×1
dual-sim ×1
gprs ×1
hotspot ×1
inetaddress ×1
java ×1
proxy ×1