2011-08-18 3 views
3

비행 모드를 활성화하고 싶지만 비행 모드를 활성화하면 블루투스, wifi를 사용할 수 없습니다. 내 목적은받는 전화와 SMS 관련 일만을 제한하는 것입니다.android에서 wifi와 bluetooth를 비활성화하지 않고 비행 모드를 활성화하십시오.

나는 다음과 같이 해봤지만 작동하지 않는다.

Settings.System.putString(getContentResolver(), 
      Settings.System.AIRPLANE_MODE_RADIOS, "cell,bluetooth"); 

어느 한 메신저 인식 비행 모드는 모든 무선 통신을 사용하지 않도록 설정의 선택을 다룰 것입니다 지금까지로이

답변

1

나에게 도움이 될 수 있습니다.

부품 만 비활성화하려면 비행 모드가 아닌 개별적으로 수행해야합니다.

종료하려는 통신 부분마다 방법을 시도하십시오.

+0

내 휴대 전화 (HTC Desire with 2.2)에서 비행 모드에서는 Wi-Fi에 액세스 할 수 있지만 Bluetooth는 사용할 수 없습니다. – Joubarc

0

시도해보십시오. 모든 장치에서 올바르게 작동하는지 보증 할 수는 없습니다.

private ITelephony getTelephonyService() { 
    try { 
     TelephonyManager oTelephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); 
     Method mGetITelephony = oTelephonyManager.getClass().getDeclaredMethod("getITelephony", new Class[] {}); 
     mGetITelephony.setAccessible(true); 
     return (ITelephony) mGetITelephony.invoke(oTelephonyManager, new Object[] {}); 
    } catch (Exception e) { 
     return null; 
    } 
} 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    try { 
     boolean retval = getTelephonyService().setRadio(false); 
     Log.v("Radio", "SetRadio : " + retval); 
    } catch (Exception e) { 
     Log.v("Radio", Log.getStackTraceString(e)); 
    } 
} 

또한 ITelephony.aidl 파일이 필요합니다. 다음과 같은 내용으로의 파일 ITelephony.aidl을 프로젝트의 src 폴더에 패키지 com.android.internal.telephony를 생성하고 생성 :

/* 
* Copyright (C) 2007 The Android Open Source Project 
* 
* Licensed under the Apache License, Version 2.0 (the "License"); 
* you may not use this file except in compliance with the License. 
* You may obtain a copy of the License at 
* 
*  http://www.apache.org/licenses/LICENSE-2.0 
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License. 
*/ 

package com.android.internal.telephony; 

import android.os.Bundle; 
import java.util.List; 

/** 
* Interface used to interact with the phone. Mostly this is used by the 
* TelephonyManager class. A few places are still using this directly. 
* Please clean them up if possible and use TelephonyManager insteadl. 
* 
* {@hide} 
*/ 
interface ITelephony { 
    /** 
    * Check to see if the radio is on or not. 
    * @return returns true if the radio is on. 
    */ 
    boolean isRadioOn(); 

    /** 
    * Toggles the radio on or off. 
    */ 
    void toggleRadioOnOff(); 

    /** 
    * Set the radio to on or off 
    */ 
    boolean setRadio(boolean turnOn); 
} 
+1

이 라디오 명령에는 MODIFY_PHONE_STATE 권한이 필요합니다.이 권한은 시스템 앱에만 부여됩니다. – mike47

2

당신은 에어 플레인 모드가 활성화되면 꺼집니다 그 어떤 라디오 변경할 수 있습니다. 비행기 모드를 활성화하기 전에 이렇게하면 무선 셀을 끌 수 있습니다.

참고 : AIRPLANE_MODE_RADIOS를 변경하면 비행기를 토글하는 시스템 버튼의 동작에 영향을줍니다.

다음은 Android 2.2에서 테스트 한 몇 가지 샘플 코드입니다.

// Toggle airplane mode. 
Settings.System.putInt(context.getContentResolver(), 
    Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1); 

// Change so that only radio cell is turned off 
// NOTE: This affects the behavior of the system button for 
// toggling air-plane mode. You might want to reset it, in order to 
// maintain the system behavior. 
Settings.System.putString(context.getContentResolver, 
    Settings.System.AIRPLANE_MODE_RADIOS, "cell"); 

// Post an intent to reload. 
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); 
intent.putExtra("state", !isEnabled); 
sendBroadcast(intent); 
+0

AIRPLANE_MODE_RADIOS는 최신 안드로이드 버전에서는 효과가없는 것 같습니다. –

관련 문제