问题标签 [android-wifi]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
wifi - 安卓wifi连接
各位会员!----am Boniface M -- android 初学者[大学生]..
我的问题是我计划开发一个 android 应用程序/中间件,它将充当网格服务。即网格计算应用程序..该应用程序需要安装在 1....n 设备中。在连接中,一个设备必须充当所有其他设备的服务器。设备之间的通信是在服务器设备的许可下通过wifi进行的。这是由一定的算法确定的[这里没有问题]。
问题是我是否应该使用一个数据库来跟踪设备正在运行的所有服务,这些服务可供其他设备访问,或者有什么方法可以直接保留所有这些信息,然后在我从另一个应用程序请求它们时检索它们安装在另一台设备上。以及我如何通过蓝牙等wifi共享文件
谢谢....
java - 如何从应用程序启用/禁用 WiFi?
我想从我的 Android 应用程序中启用/禁用 wifi。我怎样才能做到这一点?
android - 连接到指定的可用 wifi 网络
从我的应用程序中,我可以在我的设备中打开/关闭 WIFI 并能够扫描可用网络,但我无法连接到指定的可用网络。这是我正在使用的代码:
android - 保持会话超过 3g 和 wifi
当 WIFI 连接丢失并且 android 自动切换到 3G 以及设备在 3G 上工作并且有 WIFI 网络可用时,我想在我的应用程序中保持会话,因此设备将使用 WIFI。在这种连接转换中,我想保留会话。我该怎么做...
android - 在android中是否可以使用wifi找到纬度和经度?
在我的应用程序中,我需要使用用户的当前位置。通过 GPS,我知道如何做到这一点,但任何人都知道如何使用 Wifi 做到这一点吗?请帮帮我,
谢谢。
android - 使用标签、Wifi 和 Gps
在第一个选项卡下动态生成 3 个选项卡正在生成一个切换按钮,使用它我可以关闭和打开 GPS 和 WIFI
我已经为 GPS 和 WIFI 编写了 java 文件。我一次又一次地逐行检查,但找不到任何错误。我已经在模拟器和android“Sony Arc mobile”中运行过。安装也很顺利,当我尝试启动时出现问题。应用程序显示消息“应用程序已意外停止,请重试”我已经参考了几乎{所有}堆栈溢出中的所有查询,并且无法为我的场景获得任何可能的答案。我尝试删除 GPS 和 WIFI 文件在应用程序中并用 TextView 替换Toggle Button然后它工作正常。
我包括我的代码,请验证它并帮助我。
主.java
包项目.sow;
导入android.app.TabActivity;
导入android.content.Intent;
导入android.content.res.Resources;
导入android.os.Bundle;
导入 android.widget.TabHost;
公共类 Main 扩展 TabActivity {
私有 TabHost tabHost;
@Override
public void onCreate(Bundle savedInstanceState) {
try{
super.onCreate(savedInstanceState);
设置内容视图(R.layout.main);
资源 res = getResources(); // 获取Drawables的资源对象
tabHost = (TabHost)findViewById(android.R.id.tabhost); //活动TabHost
TabHost.TabSpec 规范;// 每个选项卡的可重用 TabSpec // 为每个选项卡
初始化一个 TabSpec 并将其添加到
TabHost spec = tabHost.newTabSpec("Start").setIndicator("Start", res.getDrawable(R.drawable.ic_sample));
spec.setContent(new Intent(this,Start.class));
tabHost.addTab(spec);
spec = tabHost.newTabSpec("Info").setIndicator("Info", res.getDrawable(R.drawable.ic_sample));
spec.setContent(new Intent().setClass(this, Info.class));
tabHost.addTab(spec);
启动.java
包项目.sow;
导入android.app.Activity;
导入 android.content.BroadcastReceiver;
导入android.content.Context;
导入 android.content.IntentFilter;
导入 android.location.LocationListener;
导入 android.location.LocationManager;
导入 android.location.LocationProvider;
导入android.net.wifi.WifiManager;
导入android.os.Bundle;
导入 android.widget.TextView;
导入 android.widget.Toast;
导入 android.widget.ToggleButton;
公共类开始扩展活动{
公共WifiManager wifi;
布尔状态;
上下文上下文;
公共文本视图文本状态;
公共位置管理器位置管理器;
公共位置监听器位置监听器;
公共广播接收器接收器;
公共位置提供者位置提供者;
WifiFilter.java
包项目.sow;
导入 java.util.List;
导入 android.content.BroadcastReceiver;
导入android.content.Context;
导入android.content.Intent;
导入android.net.wifi.ScanResult;
导入android.net.wifi.WifiManager;
导入android.util.Log;
导入 android.widget.Toast;
公共类 WiFiFilter 扩展 BroadcastReceiver {
private static final String TAG = "WiFiFilter";
开始开始;
公共 WiFiFilter(开始开始) {
super();
this.start=开始;
}
//准备隐藏SSID并保存wifi配置以备后用
@Override
public void onReceive(Context c, Intent intent) {
List results = start.wifi.getScanResults();
列出结果2 = null;
扫描结果过滤器 = null;
//过滤 SSID
for(ScanResult filterresult : results ){
if(filterresult.SSID=="VOLSBB")
{ results2
= results;}
}
//检查信号电平
for (ScanResult result : results2) {
if (filter == null
|| WifiManager.compareSignalLevel(filter.level, result.level) < 0)
filter = result;
尝试{
WifiManager.ACTION_PICK_WIFI_NETWORK.equals(filter);
}
catch(Exception e){String res="Exception:No network";Toast.makeText(start, res, Toast.LENGTH_LONG).show();};
}
String message = String.format("连接到 S0W");
if(filter.SSID != null){
//Toast.makeText(start, message, Toast.LENGTH_LONG).show();
Log.d(TAG, "onReceive() 消息:" + 消息);
}
} }
gpsLocation.java
包项目.sow;
导入项目.sow.CustomWebView;
导入android.location.Criteria;
导入android.location.GpsStatus;
导入android.location.Location;
导入 android.location.LocationListener;
导入 android.location.LocationManager;
导入android.os.Bundle;
导入project.sow.Start;
公共类 gpsLocation 实现 LocationListener{
开始 sowWifigps;
公共位置 currentBestLocation;
公共位置位置;
GpsStatus 状态;
CustomWebView webviewgps;
双a;
双乙;
@SuppressWarnings("未使用")
私有字符串 bestProvider;
//公共位置管理器位置管理器;
公共字符串提供者1;
公共gpsLocation(开始sowWifigps){
超级();
this.sowWifigps=sowWifigps;
// TODO 自动生成的构造函数存根
Criteria criteria = new Criteria();
//bestProvider = sowWifigps.locationManager.getBestProvider(criteria, false);
尝试{
if(LocationManager.GPS_PROVIDER==null){
provider1 = LocationManager.NETWORK_PROVIDER;
}
否则 {provider1=LocationManager.GPS_PROVIDER;}
}catch( Exception e){ provider1=sowWifigps.locationManager.getBestProvider(criteria, false);}
}
@Override
public void onLocationChanged(Location location) {
// TODO 自动生成的方法存根
sowWifigps.locationManager.requestLocationUpdates(provider1, 12000, 200、sowWifigps.locationListener);
}
@Override
public void onProviderDisabled(String provider) {
// TODO 自动生成的方法存根
//provider = LocationManager.NETWORK_PROVIDER;
currentBestLocation=sowWifigps.locationManager.getLastKnownLocation(provider1);
a=currentBestLocation.getLatitude();
b=currentBestLocation.getLongitude();
webviewgps.loadUrl(" http://localhost/mobile/default_mobile.php?lat= "+a+"&long="+b); //更改为站点名称
}
@Override
public void onProviderEnabled(String provider) {
// TODO 自动生成的方法存根
sowWifigps.locationManager.requestLocationUpdates(provider1, 12000, 200, sowWifigps.locationListener);
a=currentBestLocation.getLatitude();
b=currentBestLocation.getLongitude();
webviewgps.loadUrl(" http://localhost/mobile/default_mobile.php?lat= "+a+"&long="+b); //更改为站点名称
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO 自动生成的方法存根
sowWifigps.locationListener.onLocationChanged(location);
}
}
我在这里展示第二个选项卡,其他类似于这个。所以我省略了它。
信息.java
包项目.sow;
导入android.app.Activity;
导入android.os.Bundle;
公共类信息扩展活动 {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
protected void onResume() {
CustomWebView webView = new CustomWebView(this);
webView.loadUrl(" http://www.google.com/?s=Info ");
设置内容视图(网络视图);
超级.onResume();
} }
CustomWebView.java
包 project.sow;
导入 android.app.ProgressDialog;
导入android.content.Context;
导入android.graphics.Bitmap;
导入android.view.View;
导入 android.webkit.WebView;
导入 android.webkit.WebViewClient;
公共类 CustomWebView 扩展 WebView {
private ProgressDialog pgBar = null;
@SuppressWarnings("未使用")
私有上下文 ctx;
公共CustomWebView(上下文上下文){
超(上下文);
this.clearCache(true);
this.clearFormData();
this.clearHistory();
this.getSettings().setJavaScriptEnabled(true);
this.getSettings().setUserAgentString(null);
this.requestFocus(View.FOCUS_DOWN);
this.setWebViewClient(new CustomWebView.CustomWebViewClient());
this.pgBar = new ProgressDialog(context);
this.pgBar.setMessage("加载中...");
ctx = 上下文;
}
私有类 CustomWebViewClient 扩展 WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
if (!CustomWebView.this.pgBar.isShowing()) {
CustomWebView.this.pgBar.show();
}
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (CustomWebView.this.pgBar.isShowing()) {
CustomWebView.this.pgBar.dismiss();
}
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
try{
view.loadUrl(url);
}catch(Exception ex){
}
返回真;
} } }
主要的.XML
样式.xml
`
ic_sample
我在清单文件中添加了以下权限
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
android - 如何检查设备是否可以通过活动 WiFi 连接访问 Internet?
我指的是设备连接到接入点但由于某种原因被阻止使用此 AP 访问互联网的情况。
android - 过滤WifiManager的扫描可能吗?
我正在尝试扫描几个无线信号的强度。为此,我使用 WifiManager,在循环中调用 startScan(),并且我有一个广播接收器来获取结果。
我的问题是:
如何仅对某些网络进行扫描?在结果中,我得到了所有可用的网络。我可以过滤扫描以仅搜索某些 bssid 吗?还是ssid?除了我的 AP 之外,我不关心其他价值观。我需要以尽可能高的频率进行扫描。
另一件事是:当我再次调用 startScan(上一次调用后 500 毫秒)时,它会停止扫描吗?因为我想最大程度地降低获得信号强度的频率,而且结果有时似乎不完整?
是否可以修改 WifiManager 类的源代码以将扫描过滤到某些 id?
非常感谢!
android-wifi - 这是检测 WiFi 网络连接的正确方法吗?
我正在为 Android 制作一个应用程序,它需要在设备连接到 WiFi 网络时做出反应,我目前正在尝试使用 BroadcastReceiver 来实现它来监控 android.net.ConnectivityManager.CONNECTIVITY_ACTION - 这种方式是否正确,或者有没有更合适的方法?
android - 如何检测何时在 Android 中建立了 WIFI 连接?
我需要检测何时通过 WIFI 进行网络连接。发送什么广播以建立有效的网络连接。我需要验证 HTTP 的有效网络连接是否存在。我应该听什么以及我需要进行哪些额外的测试才能知道存在有效的连接。