小编dan*_*iel的帖子

如何以编程方式创建访问点

我已经编写了代码来为Android设备创建一个访问点.我已经在模拟器和真实设备上进行了测试.但它不起作用.我哪里弄错了?

public class MainWAP extends Activity {

    WifiManager wifiManager;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_wap);
    }

    public void openWifi(View v) {
        createWifiAccessPoint();
    }

    private void createWifiAccessPoint() {
        if (wifiManager.isWifiEnabled()) {
            wifiManager.setWifiEnabled(false);
        }
        Method[] wmMethods = wifiManager.getClass().getDeclaredMethods();
        boolean methodFound = false;
        for (Method method: wmMethods) {
            if (method.getName().equals("setWifiApEnabled")) {
                methodFound = true;
                WifiConfiguration netConfig = new WifiConfiguration();
                netConfig.SSID = "AccessPoint";
                netConfig.allowedAuthAlgorithms.set(
                    WifiConfiguration.AuthAlgorithm.OPEN);
                try {
                    boolean apstatus = (Boolean) method.invoke(
                        wifiManager, netConfig, true);
                    for (Method isWifiApEnabledmethod: wmMethods) {
                        if (isWifiApEnabledmethod.getName().equals( …
Run Code Online (Sandbox Code Playgroud)

android

20
推荐指数
2
解决办法
1万
查看次数

标签 统计

android ×1