모든 것은 와이파이sleep_policy 프롬프트 시작

4953 단어 android
title:모든 것은wifisleep_정책 알림 시작date: 2016-02-17 12:25:59
tags: 안드로이드 보안
오늘 버그를 수정하고 A인터페이스에서 블루투스를 켜고 장치를 연결하여 데이터를 전송하기 시작합니다. 이때 페이지 B로 이동합니다. 페이지 B를 닫고 A로 돌아갈 때 블루투스가 끊깁니다. 로그 로그는 다음과 같습니다.
    02-17 10:55:49.024 W/Settings: *Setting wifi_sleep_policy has moved from android.provider.Settings.System to android.provider.Settings.Global, value is unchanged*.
    02-17 10:55:49.026 W/System.err: java.io.IOException: bt socket closed, read return: -1
    02-17 10:55:49.058 W/System.err:     at android.bluetooth.BluetoothSocket.read(BluetoothSocket.java:508)
    02-17 10:55:49.058 W/System.err:     at android.bluetooth.BluetoothInputStream.read(BluetoothInputStream.java:60)
    02-17 10:55:49.058 W/System.err:     at xxx.xxx.A.readData(A.java:335)
    02-17 10:55:49.058 W/System.err:     at xxx.xxx.xxx.access$500(A.java:96)
    02-17 10:55:49.059 W/System.err:     at xxx.A.xxx$2.run(A.java:285)
    02-17 10:55:49.059 W/System.err:     at java.lang.Thread.run(Thread.java:818)
    02-17 10:55:49.129 I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@a41b2b9 time:6315482
    02-17 10:55:49.912 I/ViewRootImpl: ViewRoot's Touch Event : ACTION_DOWN
    02-17 10:55:50.005 I/ViewRootImpl: ViewRoot's Touch Event : ACTION_UP

사체 부분은 내가 의심하는 부분인데 블루투스가 끊어진 원인이라고 생각한다.
Setting wifi_sleep_policy has moved from android.provider.Settings.System to android.provider.Settings.Global, value is unchanged.
wifi_sleep_정책 이 설정은android에서 가져왔습니다.provider.Settings.System이 android로 이동했습니다.provider.Settings.글로벌, 하지만 그 값은 변하지 않았다.
그것은 서로 다른 버전의 sdk가 초래한 이 힌트입니다.그래서 먼저 찾아본 빙을 기록하는 김에
이 시스템 설정을 사용하는 이유는 와이파이가 휴면 상태에서는 기본적으로 연결되지 않기 때문이다. 이때 우리가 연결을 유지해야 할 때 어떻게 해결해야 할지 와이파이를 휴면으로 설정할 때 연결을 유지해야 한다.public void WifiNeverDormancy(Context mContext) { ContentResolver resolver = mContext.getContentResolver();
               int value = Settings.System.getInt(resolver, Settings.System.WIFI_SLEEP_POLICY,  Settings.System.WIFI_SLEEP_POLICY_DEFAULT);  
               final SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(mContext);  

               Editor editor = prefs.edit();  
               editor.putInt(mContext.getString(R.string.wifi_sleep_policy_default), value);   

               editor.commit();  
               if(Settings.System.WIFI_SLEEP_POLICY_NEVER != value)  
               {  
                  Settings.System.putInt(resolver, Settings.System.WIFI_SLEEP_POLICY, Settings.System.WIFI_SLEEP_POLICY_NEVER);  

               }  
               System.out.println("wifi value:"+value);  
            }  

위의 코드는 현재 시스템의 와이파이 설정을 저장하고 휴면으로 설정할 때 끊임없이 켜는 것입니다.인터넷을 사용할 필요가 없을 때sharedpreferences에서 꺼내서 수정 전의 모드로 복원합니다.코드는 다음과 같다.
              /**
                 *   wifi  
                 *
                 * @param context
                 */
                @SuppressWarnings("deprecation")
                public static void reductionWifiSleepPolicy(Context context) {
                    SharedPreferences sp = AppContext.getSharedPreferences();
                    int wifi_sleep_policy = sp.getInt("wifi_sleep_policy", 0);
                    Settings.System.putInt(context.getContentResolver(),
                            android.provider.Settings.System.WIFI_SLEEP_POLICY,
                            wifi_sleep_policy);
                }

이건 아무 문제 없을 것 같아서요.
어떤 힌트를 보면 시스템에서android를 찾을 수 없나요?provider.Settings.System.WIFI_SLEEP_POLICY 이 값은android로 변경됩니다.provider.Settings.Global.WIFI_SLEEP_POLICY로 인한 문제는요?
그래서 나는 Settings를 눌렀다.System.WIFI_SLEEP_POLICY 이것은 소스 가치가 있습니다:
         /** @deprecated */
                @Deprecated
                public static final String WIFI_SLEEP_POLICY = "wifi_sleep_policy";

이미 기한이 지났는데, 그럼 무엇으로 대체합니까?그게 바로 android일 거예요.provider.Settings.Global.WIFI_SLEEP_폴리시죠?
홈페이지 한번 가보세요.
기한이 지났어요.
그리고 다시 눌러서 Settings로 옮겼구나.글로벌에서 Settings를 다시 보세요.Global 소개
Global system settings, containing preferences that always apply identically to all defined users. Applications can read these but are not allowed to write; like the “Secure” settings, these are for preferences that the user must explicitly modify through the system UI or specialized APIs for those values.
너의 응용 프로그램은 이 설정들을 읽을 수 있지만, 쓸 수는 없다.
즉, sdk17부터 이것들은 읽기만 하는 것이기 때문에 쓸 수 없다.코드에 쓰고 싶으면, sdk<17용 Settings를 사용하십시오.시스템, sdk>=17용 Settings.글로벌, 하지만 secure 권한이 필요합니다. 그리고mainfest에 가세요.xml에 이 권한을 쓰십시오. as는 시스템 수준의 응용 프로그램에서만 이 권한을 사용할 수 있음을 알려 줍니다.못 쓰겠어.
즉 sdk17부터 와이파이를 휴면 상태에서 연결할 수 있도록 코드를 설정할 수 없다는 것이다.(여러분 좋은 방법 있으면 추천해 주세요)
마지막으로 이 블루투스가 끊긴 문제는 와이파이 설정과 무관하지만 이번 검색은 나로 하여금 오늘 헛수고를 하지 않았다는 것을 알게 했다.
4
  • 참조http://developer.android.com/intl/zh-cn/reference/android/provider/Settings.System.html#putInt(android.content.ContentResolver,%20java.lang.String,%20int)
  • 좋은 웹페이지 즐겨찾기