시도해보십시오. 모든 장치에서 올바르게 작동하는지 보증 할 수는 없습니다.
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);
}
내 휴대 전화 (HTC Desire with 2.2)에서 비행 모드에서는 Wi-Fi에 액세스 할 수 있지만 Bluetooth는 사용할 수 없습니다. – Joubarc