从我的应用程序连接 wi-fi
Connect wi-fi from my application
我正在开发开箱即用体验应用程序。我必须连接
来自我的自定义应用程序的 wi-fi,不使用设备 wifi
设置。
我已经完成了,从 wifi 管理器获取 wi-fi 网络列表。
你能指导我如何从我的应用程序连接 wifi 吗?
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();
}
});
}
如何设置给定的wifi密码manager.could请帮帮我。
Intent resetIntent = new Intent("android.intent.action.MASTER_CLEAR");
if (getIntent().getBooleanExtra(SHUTDOWN_INTENT_EXTRA, false)) {
resetIntent.putExtra(SHUTDOWN_INTENT_EXTRA, true);
}
sendBroadcast(resetIntent);
我正在开发开箱即用体验应用程序。我必须连接 来自我的自定义应用程序的 wi-fi,不使用设备 wifi 设置。 我已经完成了,从 wifi 管理器获取 wi-fi 网络列表。
你能指导我如何从我的应用程序连接 wifi 吗?
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();
}
});
}
如何设置给定的wifi密码manager.could请帮帮我。
Intent resetIntent = new Intent("android.intent.action.MASTER_CLEAR");
if (getIntent().getBooleanExtra(SHUTDOWN_INTENT_EXTRA, false)) {
resetIntent.putExtra(SHUTDOWN_INTENT_EXTRA, true);
}
sendBroadcast(resetIntent);