简体   繁体   English

以编程方式禁用android wifi热点的最佳方法是什么?

[英]What's the best way to programmatically disable android wifi hotspot?

I created a test wifi hotspot app. 我创建了一个测试wifi热点应用。 The app essentially enables and disables wifi hotspot functionality for the android platform(tested from 2.3 to 4.1). 该应用程序实质上为android平台启用和禁用了wifi热点功能(测试范围为2.3到4.1)。

I've noticed two issues with the app that I'm hoping to get some help with. 我注意到该应用程序有两个问题,希望能对此有所帮助。

1)I'm unable to stop the wifi hotspot if the hotspot has been enabled for more than 30 minutes(average timing). 1)如果启用热点超过30分钟(平均时间),我将无法停止wifi热点。 I'm able to stop the hotspot just fine if it hasn't been started for very long. 如果尚未启动很长时间,我就可以停止热点。 I use the following code to stop: 我使用以下代码停止:

    // Disable wifi hotspot
private static void stopAccessPoint() {
    try
    {
        Method[] wmMethods = wifi.getClass().getDeclaredMethods();

        for (Method method : wmMethods) {
            if (method.getName().equals("setWifiApEnabled")) {
                try {
                    method.invoke(wifi, null, false);
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    catch(Exception e)
    {
        Log.d(TAG, errorStoppingHotspotMessage);

    }

2)The wifi hotspot loses connectivity to the internet after being in use for long periods of time. 2)wifi热点长期使用后失去与互联网的连接。 I noticed that it occurs more frequently when in use around other wireless networks, so I thought maybe it could be due to interference. 我注意到它在其他无线网络中使用时更频繁地发生,因此我认为可能是由于干扰。

I'm able to start the wifi hotspot just fine with no issues at any given time. 我能够在任意给定时间启动wifi热点而没有任何问题。 All research pointed me to the above code that I'm already using for disabling the hotspot. 所有研究都将我指向了上面我用于禁用热点的代码。

Have any of you guys seen these issues before? 你们有没有看过这些问题? It's really hard to test the issues considering the amount of time it takes for the issues to occur. 考虑到问题发生所花费的时间,真的很难测试问题。

Any help will be greatly appreciated. 任何帮助将不胜感激。

1) You might want to change your e.printStackTrace(); 1)您可能想要更改e.printStackTrace(); into actual Logging, I use the same code and it works fine no matter how long I wait for it. 在实际的日志记录中,我使用相同的代码,无论我等待多长时间,它都可以正常工作。

2) Noticed the same, not sure which it relates too, however if there's "constant" traffic, it never drops. 2)注意相同的内容,不确定是否也相关,但是,如果流量“恒定”,则流量永远不会下降。 Sometimes I have to disable the hotspot and reenable it quickly to fix this, but sometimes it's my data plan that drops too... Maybe the operator doesn't want us to hotspot their data plan? 有时我必须禁用热点并快速重新启用它才能解决此问题,但有时也是我的数据计划下降了……也许运营商不希望我们对他们的数据计划进行热点?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM