gpt4 book ai didi

java - 无法在 android N 中获取范围内的路由器

转载 作者:太空宇宙 更新时间:2023-11-03 13:10:35 25 4
gpt4 key购买 nike

我想让所有路由器都在范围内并在 ListView 中显示它,但在 android n 及更高版本中面临问题。我能够获取所有路由器并在 android 5 lollipop 和 lollipop 以下的 ListView 中显示它,但它在 android N 及更高版本中不起作用。我正在分段进行。

这是我的代码。

    public class Add_Router extends android.support.v4.app.Fragment {
public Add_Router() {
}

ArrayList<AR_Router> ar_router;
WifiManager mWifiManager;
ListView lv;
ProgressDialog pd;
String adm_token;

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.frag_addrouter, container, false);
setHasOptionsMenu(true);
adm_token = getArguments().getString("adm_token");
pd = new ProgressDialog(getActivity(), R.style.pdtheme);
pd.setCancelable(false);
pd.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
ar_router = new ArrayList<>();
lv = (ListView) v.findViewById(R.id.lv);

//get all wifi devices
pd.show();
mWifiManager = (WifiManager) getActivity().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
getActivity().registerReceiver(mWifiScanReceiver,
new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
mWifiManager.startScan();


return v;
}

private final BroadcastReceiver mWifiScanReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context c, Intent intent) {
try{
if (intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
List<ScanResult> mScanResults = mWifiManager.getScanResults();
if (!ar_router.isEmpty()) {
ar_router.clear();
}
for (int i = 0; i < mScanResults.size(); i++) {
String router_name = mScanResults.get(i).SSID.toString();
String router_mac = mScanResults.get(i).BSSID.toString();
Log.d("router : ","rout:"+router_name);
AR_Router router = new AR_Router();
router.arString_routerName = router_name;
router.arString_routerMac = router_mac;
ar_router.add(router);

}
CustomAdapter ca = new CustomAdapter(getActivity(), R.layout.cstm_router, R.id.tv_router_Name, ar_router);
lv.setAdapter(ca);
pd.dismiss();
}}catch (Exception e){
e.printStackTrace();
}
}
};

这是我的自定义适配器。

     class CustomAdapter extends ArrayAdapter<AR_Router> {
public CustomAdapter(Context context, int resource, int textViewResourceId, ArrayList<AR_Router> objects) {
super(context, resource, textViewResourceId, objects);
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View v = inflater.inflate(R.layout.cstm_router, parent, false);
final TextView router_name = (TextView) v.findViewById(R.id.tv_router_Name);
final TextView router_mac = (TextView) v.findViewById(R.id.router_mac);

AR_Router ar_rout = ar_router.get(position);
router_name.setText(ar_rout.arString_routerName);
router_mac.setText(ar_rout.arString_routerMac);

return v;

}
}

这是数组类

     //array class
private class AR_Router {
String arString_routerName;
String arString_routerMac;
}

最佳答案

尝试使用位置开启。打开您的位置,然后尝试。在 list 文件 ACCESS_FINE_LOCATION 中添加权限。

关于java - 无法在 android N 中获取范围内的路由器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46343761/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com