Java 如何通过从spinner选择wifi来启用wifi WIFI=(微调器)findviewbyd(R.id.WIFI); //使用字符串数组和默认微调器布局创建ArrayAdapter ArrayAdapter=ArrayAdapter.createFromResource(此, R.array.WIFI、android.R.layout.simple\u下拉菜单\u项目\u 1line); //指定显示选项列表时要使用的布局 setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项); //将适配器应用于微调器 WIFI.setAdapter(适配器); WIFI.setOnItemSelectedListener(新的MyOnItemSelectedListener());
如何通过从微调器中选择来启用wifi。Java 如何通过从spinner选择wifi来启用wifi WIFI=(微调器)findviewbyd(R.id.WIFI); //使用字符串数组和默认微调器布局创建ArrayAdapter ArrayAdapter=ArrayAdapter.createFromResource(此, R.array.WIFI、android.R.layout.simple\u下拉菜单\u项目\u 1line); //指定显示选项列表时要使用的布局 setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项); //将适配器应用于微调器 WIFI.setAdapter(适配器); WIFI.setOnItemSelectedListener(新的MyOnItemSelectedListener());,java,android,android-intent,Java,Android,Android Intent,如何通过从微调器中选择来启用wifi。 我将感谢您将这段代码添加到您的听众中 WIFI = (Spinner) findViewById(R.id.WIFI); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
我将感谢您将这段代码添加到您的听众中
WIFI = (Spinner) findViewById(R.id.WIFI);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.WIFI, android.R.layout.simple_dropdown_item_1line);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
WIFI.setAdapter(adapter);
WIFI.setOnItemSelectedListener(new MyOnItemSelectedListener());
或用于切换行为
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(true);
您可能需要向清单中添加一些权限
wifi.setWifiEnabled(!wifi.isWifiEnabled());
有关更多选项,请参阅
据我所知,热点功能没有API。您必须使用反射来调用这些方法…要执行此操作,您需要获取微调器的文本(或选择),然后需要切换WiFi设置 在微调器上获取选定项
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
String Text = mySpinner.getSelectedItem().toString();
if (Text.equals("on"){
//put below code here
} else {
//put more code here
}
WifiManager wifiManager = (WifiManager)this.context.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(true);