【问题标题】:Connect wi-fi from my application从我的应用程序连接 wi-fi
【发布时间】:2017-09-14 02:35:12
【问题描述】:

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

【问题讨论】:

  • 你能说清楚你到底需要什么,因为不清楚。
  • 1.on wifi 2.get wifi networks 3.connect wifi from my application only。 1和2完成。无需使用设备 wifi 设置即可从我的应用程序完成 WiFi 连接。我附上了屏幕截图。

标签: android android-studio android-wifi


【解决方案1】:
Intent resetIntent = new Intent("android.intent.action.MASTER_CLEAR");
                            if (getIntent().getBooleanExtra(SHUTDOWN_INTENT_EXTRA, false)) {
                             resetIntent.putExtra(SHUTDOWN_INTENT_EXTRA, true);
                                 }
                            sendBroadcast(resetIntent);

【讨论】:

    猜你喜欢
    • 2011-07-11
    • 1970-01-01
    • 2014-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-25
    • 1970-01-01
    相关资源
    最近更新 更多