gpt4 book ai didi

android - 从我的应用程序连接 wi-fi

转载 作者:行者123 更新时间:2023-11-30 00:35:33 26 4
gpt4 key购买 nike

enter image description here

我正在开发开箱即用的体验应用程序。我必须连接 来 self 的自定义应用程序的 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 管理器设置给定密码。你能帮帮我吗?

最佳答案

Intent resetIntent = new Intent("android.intent.action.MASTER_CLEAR");
if (getIntent().getBooleanExtra(SHUTDOWN_INTENT_EXTRA, false)) {
resetIntent.putExtra(SHUTDOWN_INTENT_EXTRA, true);
}
sendBroadcast(resetIntent);

关于android - 从我的应用程序连接 wi-fi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43469040/

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