WIFI_SLEEP_POLICY_NEVER如何在API-17集? [英] WIFI_SLEEP_POLICY_NEVER how to set in API-17?

查看:627
本文介绍了WIFI_SLEEP_POLICY_NEVER如何在API-17集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code,我的目标是API-15

I was using following code , my target is API-15

android.provider.Settings.System.putInt(cr, 
                        android.provider.Settings.System.WIFI_SLEEP_POLICY, 
                        android.provider.Settings.System.WIFI_SLEEP_POLICY_NEVER);

当code平台上的API-17,我得到了logcat中warnigns运行,

When the code runs on platform API-17 I get warnigns in the logcat,

设置wifi_sleep_policy已经从android.provider.Settings.System搬到android.provider.Settings.Global,价值是不变的。

Setting wifi_sleep_policy has moved from android.provider.Settings.System to android.provider.Settings.Global, value is unchanged.

因此​​,我所做的设置我的项目的目标后,API-17,并以此code

So what I did after that was set my project target to APi-17 and used this code

        if(Build.VERSION.SDK_INT < 17)
        {
            android.provider.Settings.System.putInt(cr, 
                        android.provider.Settings.System.WIFI_SLEEP_POLICY, 
                        android.provider.Settings.System.WIFI_SLEEP_POLICY_NEVER);
        }
        else            
        {               
            android.provider.Settings.Global.putInt(cr, 
                    android.provider.Settings.Global.WIFI_SLEEP_POLICY, 
                    android.provider.Settings.Global.WIFI_SLEEP_POLICY_NEVER);

        }

因此​​我开始在平台下面SecurityException异常API-17

As a result I started getting following SecurityException in platform Api-17

         java.lang.SecurityException: Permission denial: writing to secure settings requires android.permission.WRITE_SECURE_SETTINGS

然后我检查了WRITE_SECURE_SETTINGS权限只对系统应用程式和我无法编译我的code用它,仿佛此权限的系统只应用程序。

Then I checked that WRITE_SECURE_SETTINGS permission is only for system apps and I was not able to compile my code with it, as if this permission is for system apps only.

所以我很困惑的是,我之前得到的是错误的或者是有什么错我的code中的警告,我想让它与API-17兼容它。

So I am confused was the warning that I got earlier was wrong or is there anything wrong with my code, I want to make it compatible it with API-17.

推荐答案

不幸的是无法从API-17再更改此设置,因为它<一个向前href=\"http://developer.android.com/reference/android/provider/Settings.System.html#WIFI_SLEEP_POLICY\"相对=nofollow>已经去precated 。

Unfortunately it is not possible to change this setting anymore from API-17 onward since it has been deprecated.

正如你所说,在 WRITE_SECURE_SETTINGS 权限只授予给系统应用等的最佳替代方案是要求用户手动设置从WiFi设置此选项:

As you said, the WRITE_SECURE_SETTINGS permission is only granted to system apps and so the best alternative is to ask the user to manually set this option from the wifi settings:

startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));

这篇关于WIFI_SLEEP_POLICY_NEVER如何在API-17集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆