本文整理汇总了Java中android.net.wifi.WifiManager.startScan方法的典型用法代码示例。如果您正苦于以下问题:Java WifiManager.startScan方法的具体用法?Java WifiManager.startScan怎么用?Java WifiManager.startScan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.wifi.WifiManager
的用法示例。
在下文中一共展示了WifiManager.startScan方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: provide
import android.net.wifi.WifiManager; //导入方法依赖的package包/类
@Override
protected void provide() {
WifiManager wifiMgr = (WifiManager) this.getContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if(wifiMgr.isWifiEnabled()) {
Log.e("wifi","enabled");
this.getContext().registerReceiver(this.wifiReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
wifiMgr.startScan();
}
else{
Log.e("wifi","not enabled");
this.finish();
}
}
示例2: refresh
import android.net.wifi.WifiManager; //导入方法依赖的package包/类
/**
* Starts a scan for networks.
*/
private void refresh() {
try {
setListAdapter(mNetworkListdapter);
if (mNetworkListdapter != null) {
// Clear the data to indicate we are waiting
mNetworkListdapter.clear();
// Refresh the View so it shows
mNetworkListdapter.notifyDataSetChanged();
}
WifiManager wifiManager = (WifiManager) getSystemService(Context
.WIFI_SERVICE);
wifiManager.startScan();
} catch (Exception ex) {
Utils.excMsg(this, "Error starting network scan", ex);
}
}
示例3: getScanResultsByBSSID
import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public static ScanResult getScanResultsByBSSID(Context context, String bssid) {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
ScanResult scanResult = null;
boolean f = wifiManager.startScan();
if (!f) {
getScanResultsByBSSID(context, bssid);
}
List<ScanResult> list = wifiManager.getScanResults();
if (list != null) {
for (int i = 0; i < list.size(); i++) {
scanResult = list.get(i);
if (scanResult.BSSID.equals(bssid)) {
break;
}
}
}
return scanResult;
}
示例4: doInBackground
import android.net.wifi.WifiManager; //导入方法依赖的package包/类
@Override
protected Void doInBackground(Void... params) {
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + networkSSID + "\"";
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
WifiManager wifiManager = (WifiManager) getBaseContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
wifiManager.addNetwork(conf);
if (!wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(true);
wifiManager.startScan();
}
int netId = wifiManager.addNetwork(conf);
wifiManager.disconnect();
wifiManager.enableNetwork(netId, true);
wifiManager.reconnect();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), "Joined to " + networkSSID, Toast.LENGTH_SHORT).show();
System.out.println("SUCCESS ");
}
});
return null;
}
示例5: onCreate
import android.net.wifi.WifiManager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
setContentView(R.layout.activity_bind_device_two);
AndroidBug54971Workaround.assistActivity(findViewById(android.R.id.content));
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= 20) {
getWindow().setStatusBarColor(getResources().getColor(R.color.bar_color));
}
llBack = (LinearLayout) findViewById(R.id.ll_back);
llBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
TextView btnSure = (TextView) findViewById(R.id.tvEditSure);
btnSure.setVisibility(View.INVISIBLE);
TextView tvTitle = (TextView) findViewById(R.id.tvTitle);
tvTitle.setText(R.string.find_devices);
txtTime = (TextView) findViewById(R.id.txtTime);
txtTime.setText("" + scanTime);
progressBar = (ColorfulRingProgressView) findViewById(R.id.spv);
new Thread(new MyThread()).start();
type = getIntent().getIntExtra("type", 0);
if (type == 1) {
((TextView) findViewById(R.id.txtTitle)).setText(R.string.add_device_two_title2);
mWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
mWifiManager.startScan();
//搜索网络并加入
WlanScan();
} else {
BluetoothScan();
}
}
示例6: connect
import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public void connect(String ssid, String pwd, WiFiStaConnectCallback callback){
if(callback == null){
return;
}
mCallback = callback;
mSSID = ssid;
mPWD = pwd;
WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
WifiConfiguration config = new WifiConfiguration();
config.SSID = "\"" + mSSID + "\"";
if(pwd.equals("")){
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
}
else{
config.preSharedKey = "\"" + mPWD + "\"";
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
}
config.status = WifiConfiguration.Status.ENABLED;
config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
if(!wifiManager.isWifiEnabled()){
wifiManager.setWifiEnabled(true);
}
wifiManager.startScan();
int networkId = wifiManager.addNetwork(config);
wifiManager.disconnect();
wifiManager.enableNetwork(networkId, true);
wifiManager.reconnect();
}
示例7: scanWifi
import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public List<ScanResult> scanWifi(){
lstWifi.clear();
final WifiManager wifi = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
if (wifi.isWifiEnabled() == false)
{
wifi.setWifiEnabled(true);
}
mContext.registerReceiver(new BroadcastReceiver()
{
@Override
public void onReceive(Context c, Intent intent)
{
lstWifi = wifi.getScanResults();;
}
}, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
wifi.startScan();
int i = 0;
while(i < 10){
i++;
try {
Thread.sleep(1000);
}catch (Exception e){
}
}
return lstWifi;
}
示例8: onRequestPermissionsResult
import android.net.wifi.WifiManager; //导入方法依赖的package包/类
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == 0x12345) {
for (int grantResult : grantResults) {
if (grantResult != PackageManager.PERMISSION_GRANTED) {
return;
}
}
WifiManager myWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
boolean wasEnabled = myWifiManager.isWifiEnabled();
if (!wasEnabled)
myWifiManager.setWifiEnabled(true);
if (myWifiManager.isWifiEnabled()) {
if (myWifiManager.startScan()) {
// List available APs
Log.d("pras", "this inside scan");
List<ScanResult> scans = myWifiManager.getScanResults();
Log.d("pras", "" + (scans == null));
Log.d("pras", "" + scans.isEmpty());
if (scans != null && !scans.isEmpty()) {
for (ScanResult scan : scans) {
int level = WifiManager.calculateSignalLevel(scan.level, 20);
//Other code
Log.d("wifi", level + "this");
}
} else {
Log.d("pras", "this inside else");
}
}
}
}
}
示例9: startScan
import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public static boolean startScan(Context context, BroadcastReceiver reciever) {
WifiManager wifiManager = (WifiManager) context
.getSystemService(Context.WIFI_SERVICE);
context.registerReceiver(reciever, new IntentFilter(
WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
boolean result = wifiManager.startScan();
return result;
}
示例10: WifiScanReceiver
import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public WifiScanReceiver(CrossfadePageTransformer crossfadePageTransformer, SetupActivity activity) {
this.crossfadePageTransformer = crossfadePageTransformer;
wifiManager = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE);
crossfadePageTransformer.setWifiNetworks(getWifiNetworks());
wifiManager.startScan();
}
示例11: getWifiScanResults
import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public static List<ScanResult> getWifiScanResults(Context context) {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
return wifiManager.startScan() ? wifiManager.getScanResults() : null;
}
示例12: getCurrentWifiScanResult
import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public static List<ScanResult> getCurrentWifiScanResult(Context context) {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
wifiManager.startScan();
return wifiManager.getScanResults();
}
示例13: connectWifi
import android.net.wifi.WifiManager; //导入方法依赖的package包/类
private void connectWifi() {
info("Connecting to WiFi");
final WifiManager manager = (WifiManager) getApplicationContext()
.getSystemService(Context.WIFI_SERVICE);
if (!manager.isWifiEnabled()) {
info("Enabling WiFi");
manager.setWifiEnabled(true);
}
if (!manager.startScan()) {
info("Could not start a WiFi scan ...");
}
final List<android.net.wifi.ScanResult> list = manager.getScanResults();
for (final android.net.wifi.ScanResult result : list) {
if (result.SSID != null
&& result.SSID.startsWith("LGR105")
&& result.SSID.endsWith(".OSC")
) {
info("Found WiFi candidate: " + result.capabilities);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
String networkSSID = result.SSID;
String networkPass = prefs.getString("wifipass", "");
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + networkSSID + "\"";
conf.preSharedKey = "\"" + networkPass + "\"";
conf.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
final int networkId = manager.addNetwork(conf);
if (networkId != -1) {
manager.disconnect();
manager.enableNetwork(networkId, true);
manager.saveConfiguration();
}
info("WiFi: Connected!");
}
}
}
示例14: WifiStrength
import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public List<Map.Entry<String, Double>> WifiStrength(){
WifiManager myWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
boolean wasEnabled = myWifiManager.isWifiEnabled();
if (!wasEnabled)
myWifiManager.setWifiEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
Log.d("pras","inside permission");
requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, 0x12345);
}
if (myWifiManager.isWifiEnabled()) {
if (myWifiManager.startScan()) {
// List available APs
Log.d("pras", "inside scan");
List<ScanResult> scans = myWifiManager.getScanResults();
Log.d("pras", "" + (scans == null));
Log.d("pras", "" + scans.isEmpty());
//int topThree = 3;
if (scans != null && !scans.isEmpty()) {
int i=0;
for (ScanResult scan : scans) {
Double level = (double)scan.level;
Log.d("frequency",scan.frequency + "");
//Other code
Log.d("pras", scan.SSID + " : " + scan.level);
// if(topThree!=0)
// Log.d("pras",scan.SSID);
wifiDetails.put(scan.BSSID,level);
}
} else {
Log.d("pras", "inside else");
}
}
}
Set<Map.Entry<String, Double>> set = wifiDetails.entrySet();
List<Map.Entry<String, Double>> list = new ArrayList<Map.Entry<String, Double>>(set);
Collections.sort( list, new Comparator<Map.Entry<String, Double>>()
{
public int compare( Map.Entry<String, Double> o1, Map.Entry<String, Double> o2 )
{
return (o2.getValue()).compareTo( o1.getValue() );
}
} );
for(int tt = 0; tt<5; tt++)
toastText+= list.get(tt).getKey()+ " : " + list.get(tt).getValue() + "\n";
for(Map.Entry<String, Double> entry:list){
Log.d("Pras",entry.getKey()+" ==== "+entry.getValue());
}
return list;
}
示例15: startScan
import android.net.wifi.WifiManager; //导入方法依赖的package包/类
public static void startScan(Context context) {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
wifiManager.startScan();
}