Android 从我的应用程序连接wi-fi
我正在开发现成的体验应用程序。我必须接通 我的定制应用程序中的wi-fi不使用设备wifi 设置。 我已经完成了,从wifi manager获取wi-fi网络列表 请您指导我,如何从我的应用程序连接wifiAndroid 从我的应用程序连接wi-fi,android,android-studio,android-wifi,Android,Android Studio,Android Wifi,我正在开发现成的体验应用程序。我必须接通 我的定制应用程序中的wi-fi不使用设备wifi 设置。 我已经完成了,从wifi manager获取wi-fi网络列表 请您指导我,如何从我的应用程序连接wifi listview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?>
listview.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View view,
int position, long id) {
AlertDialog.Builder alert = new AlertDialog.Builder(WifiActivity.this);
str_wifi_nt_name = arg0.getItemAtPosition(position).toString();
alert.setTitle(str_wifi_nt_name);
LinearLayout layout = new LinearLayout(WifiActivity.this);
layout.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(20, 0, 30, 0);
wifi_password = new EditText(WifiActivity.this);
wifi_password.setHint("wi-fi password");
str_wifi_password=wifi_password.getText().toString();
layout.addView(wifi_password, params);
alert.setView(layout);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
WifiConfiguration wifiConfig = new WifiConfiguration();
wifiConfig.SSID = String.format("\"%s\"", str_wifi_nt_name);
wifiConfig.preSharedKey = String.format("\"%s\"", str_wifi_password);
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
alert.show();
}
});
}
listview.setOnItemClickListener(新的OnItemClickListener()
{
@凌驾
public void onItemClick(AdapterView arg0,视图,
内部位置,长id){
AlertDialog.Builder alert=新建AlertDialog.Builder(WifiActivity.this);
str_wifi_nt_name=arg0.getItemAtPosition(position.toString();
警报。设置标题(str_wifi_nt_name);
LinearLayout布局=新的LinearLayout(WifiActivity.this);
布局。设置方向(线性布局。垂直);
LinearLayout.LayoutParams params=新的LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL\u父级,LinearLayout.LayoutParams.WRAP\u内容);
参数设置边距(20,0,30,0);
wifi_password=新编辑文本(WifiActivity.this);
wifi_password.setHint(“wi-fi密码”);
str_wifi_password=wifi_password.getText().toString();
布局。添加视图(wifi_密码,参数);
alert.setView(布局);
alert.setPositiveButton(“确定”,新的DialogInterface.OnClickListener(){
public void onClick(对话框接口对话框,int whichButton){
WifiConfiguration wifiConfig=新的WifiConfiguration();
wifiConfig.SSID=String.format(“\%s\”,str\u wifi\u nt\u name);
wifiConfig.preSharedKey=String.format(“\%s\”,str\u wifi\u密码);
}
});
alert.setNegativeButton(“取消”,新建DialogInterface.OnClickListener()){
public void onClick(对话框接口对话框,int whichButton){
}
});
alert.show();
}
});
}
如何设置wifi管理器的密码。请告诉我 您能否明确您需要什么,因为不清楚。1.使用wifi 2.获取wifi网络3.仅从我的应用程序连接wifi。1和2已完成。通过我的应用程序进行WiFi连接,无需使用设备WiFi设置。我附上了屏幕截图。
Intent resetIntent = new Intent("android.intent.action.MASTER_CLEAR");
if (getIntent().getBooleanExtra(SHUTDOWN_INTENT_EXTRA, false)) {
resetIntent.putExtra(SHUTDOWN_INTENT_EXTRA, true);
}
sendBroadcast(resetIntent);