NeighboringCellInfo.aidl
package android.telephony;<br />parcelable NeighboringCellInfo;
ITelephony.aidl
/*<br /> * Copyright (C) 2007 The Android Open Source Project<br /> *<br /> * Licensed under the Apache License, Version 2.0 (the "License");<br /> * you may not use this file except in compliance with the License.<br /> * You may obtain a copy of the License at<br /> *<br /> * http://www.apache.org/licenses/LICENSE-2.0<br /> *<br /> * Unless required by applicable law or agreed to in writing, software<br /> * distributed under the License is distributed on an "AS IS" BASIS,<br /> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<br /> * See the License for the specific language governing permissions and<br /> * limitations under the License.<br /> */<br />package com.android.internal.telephony;<br />import android.os.Bundle;<br />import java.util.List;<br />import android.telephony.NeighboringCellInfo;<br />/**<br /> * Interface used to interact with the phone. Mostly this is used by the<br /> * TelephonyManager class. A few places are still using this directly.<br /> * Please clean them up if possible and use TelephonyManager insteadl.<br /> *<br /> * {@hide}<br /> */<br />interface ITelephony {<br /> /**<br /> * Dial a number. This doesn't place the call. It displays<br /> * the Dialer screen.<br /> * @param number the number to be dialed. If null, this<br /> * would display the Dialer screen with no number pre-filled.<br /> */<br /> void dial(String number);<br /> /**<br /> * Place a call to the specified number.<br /> * @param number the number to be called.<br /> */<br /> void call(String number);<br /> /**<br /> * If there is currently a call in progress, show the call screen.<br /> * The DTMF dialpad may or may not be visible initially, depending on<br /> * whether it was up when the user last exited the InCallScreen.<br /> *<br /> * @return true if the call screen was shown.<br /> */<br /> boolean showCallScreen();<br /> /**<br /> * Variation of showCallScreen() that also specifies whether the<br /> * DTMF dialpad should be initially visible when the InCallScreen<br /> * comes up.<br /> *<br /> * @param showDialpad if true, make the dialpad visible initially,<br /> * otherwise hide the dialpad initially.<br /> * @return true if the call screen was shown.<br /> *<br /> * @see showCallScreen<br /> */<br /> boolean showCallScreenWithDialpad(boolean showDialpad);<br /> /**<br /> * End call or go to the Home screen<br /> *<br /> * @return whether it hung up<br /> */<br /> boolean endCall();<br /> /**<br /> * Answer the currently-ringing call.<br /> *<br /> * If there's already a current active call, that call will be<br /> * automatically put on hold. If both lines are currently in use, the<br /> * current active call will be ended.<br /> *<br /> * TODO: provide a flag to let the caller specify what policy to use<br /> * if both lines are in use. (The current behavior is hardwired to<br /> * "answer incoming, end ongoing", which is how the CALL button<br /> * is specced to behave.)<br /> *<br /> * TODO: this should be a oneway call (especially since it's called<br /> * directly from the key queue thread).<br /> */<br /> void answerRingingCall();<br /> /**<br /> * Silence the ringer if an incoming call is currently ringing.<br /> * (If vibrating, stop the vibrator also.)<br /> *<br /> * It's safe to call this if the ringer has already been silenced, or<br /> * even if there's no incoming call. (If so, this method will do nothing.)<br /> *<br /> * TODO: this should be a oneway call too (see above).<br /> * (Actually *all* the methods here that return void can<br /> * probably be oneway.)<br /> */<br /> void silenceRinger();<br /> /**<br /> * Check if we are in either an active or holding call<br /> * @return true if the phone state is OFFHOOK.<br /> */<br /> boolean isOffhook();<br /> /**<br /> * Check if an incoming phone call is ringing or call waiting.<br /> * @return true if the phone state is RINGING.<br /> */<br /> boolean isRinging();<br /> /**<br /> * Check if the phone is idle.<br /> * @return true if the phone state is IDLE.<br /> */<br /> boolean isIdle();<br /> /**<br /> * Check to see if the radio is on or not.<br /> * @return returns true if the radio is on.<br /> */<br /> boolean isRadioOn();<br /> /**<br /> * Check if the SIM pin lock is enabled.<br /> * @return true if the SIM pin lock is enabled.<br /> */<br /> boolean isSimPinEnabled();<br /> /**<br /> * Cancels the missed calls notification.<br /> */<br /> void cancelMissedCallsNotification();<br /> /**<br /> * Supply a pin to unlock the SIM. Blocks until a result is determined.<br /> * @param pin The pin to check.<br /> * @return whether the operation was a success.<br /> */<br /> boolean supplyPin(String pin);<br /> /**<br /> * Handles PIN MMI commands (PIN/PIN2/PUK/PUK2), which are initiated<br /> * without SEND (so <code>dial</code> is not appropriate).<br /> *<br /> * @param dialString the MMI command to be executed.<br /> * @return true if MMI command is executed.<br /> */<br /> boolean handlePinMmi(String dialString);<br /> /**<br /> * Toggles the radio on or off.<br /> */<br /> void toggleRadioOnOff();<br /> /**<br /> * Set the radio to on or off<br /> */<br /> boolean setRadio(boolean turnOn);<br /> /**<br /> * Request to update location information in service state<br /> */<br /> void updateServiceLocation();<br /> /**<br /> * Enable location update notifications.<br /> */<br /> void enableLocationUpdates();<br /> /**<br /> * Disable location update notifications.<br /> */<br /> void disableLocationUpdates();<br /> /**<br /> * Enable a specific APN type.<br /> */<br /> int enableApnType(String type);<br /> /**<br /> * Disable a specific APN type.<br /> */<br /> int disableApnType(String type);<br /> /**<br /> * Allow mobile data connections.<br /> */<br /> boolean enableDataConnectivity();<br /> /**<br /> * Disallow mobile data connections.<br /> */<br /> boolean disableDataConnectivity();<br /> /**<br /> * Report whether data connectivity is possible.<br /> */<br /> boolean isDataConnectivityPossible();<br /> Bundle getCellLocation();<br /> /**<br /> * Returns the neighboring cell information of the device.<br /> */<br /> List<NeighboringCellInfo> getNeighboringCellInfo();<br /> int getCallState();<br /> int getDataActivity();<br /> int getDataState();<br /> /**<br /> * Returns the current active phone type as integer.<br /> * Returns TelephonyManager.PHONE_TYPE_CDMA if RILConstants.CDMA_PHONE<br /> * and TelephonyManager.PHONE_TYPE_GSM if RILConstants.GSM_PHONE<br /> */<br /> int getActivePhoneType();<br /> /**<br /> * Returns the CDMA ERI icon index to display<br /> */<br /> int getCdmaEriIconIndex();<br /> /**<br /> * Returns the CDMA ERI icon mode,<br /> * 0 - ON<br /> * 1 - FLASHING<br /> */<br /> int getCdmaEriIconMode();<br /> /**<br /> * Returns the CDMA ERI text,<br /> */<br /> String getCdmaEriText();<br /> /**<br /> * Returns true if CDMA provisioning needs to run.<br /> */<br /> boolean getCdmaNeedsProvisioning();<br /> /**<br /> * Returns the unread count of voicemails<br /> */<br /> int getVoiceMessageCount();<br /> /**<br /> * Returns the network type<br /> */<br /> int getNetworkType();</p><p> /**<br /> * Return true if an ICC card is present<br /> */<br /> boolean hasIccCard();<br />}<br />
PhoneCallActivity .java
package com.geolo.pcp.android;<br />import java.lang.reflect.Method;<br />import com.android.internal.telephony.ITelephony;<br />import android.app.Activity;<br />import android.content.Context;<br />import android.media.AudioManager;<br />import android.os.Bundle;<br />import android.telephony.PhoneStateListener;<br />import android.telephony.ServiceState;<br />import android.telephony.SignalStrength;<br />import android.telephony.TelephonyManager;<br />import android.util.Log;<br />public class PhoneCallActivity extends Activity{<br />private PhoneCallListener mPhoneCallListener;<br />private TelephonyManager mTelephonyManager;<br />//private PhoneStateListener mPhoneStateListener;<br />private AudioManager mAudioManager;<br />@Override<br />protected void onCreate(Bundle savedInstanceState) {<br />super.onCreate(savedInstanceState);<br />mPhoneCallListener = new PhoneCallListener();<br />mTelephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);<br />mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);<br />mTelephonyManager.listen(mPhoneCallListener, PhoneCallListener.LISTEN_CALL_STATE);<br />//mTelephonyManager.listen(mPhoneCallListener, PhoneCallListener.LISTEN_SERVICE_STATE);<br />//mTelephonyManager.listen(mPhoneCallListener, PhoneCallListener.LISTEN_DATA_CONNECTION_STATE);<br />}<br />/**<br /> * 利用JAVA反射機制調用ITelephony的endCall()結束通話。<br /> */<br />private void endCall() {<br />// 初始化iTelephony<br />Class<TelephonyManager> c = TelephonyManager.class;<br />Method getITelephonyMethod = null;<br />try {<br />// 擷取所有public/private/protected/預設<br />// 方法的函數,如果只需要擷取public方法,則可以調用getMethod.<br />getITelephonyMethod = c.getDeclaredMethod("getITelephony",(Class[]) null);<br />// 將要執行的方法對象設定是否進行訪問檢查,也就是說對於public/private/protected/預設<br />// 我們是否能夠訪問。值為 true 則指示反射的對象在使用時應該取消 Java 語言訪問檢查。值為 false<br />// 則指示反射的對象應該實施 Java 語言訪問檢查。<br />getITelephonyMethod.setAccessible(true);<br />ITelephony iTelephony = (ITelephony) getITelephonyMethod.invoke(mTelephonyManager, (Object[]) null);<br />iTelephony.endCall();<br />Log.v(this.getClass().getName(), "endCall......");<br />} catch (Exception e) {<br />Log.e(this.getClass().getName(), "endCallError", e);<br />}<br />}<br />public class PhoneCallListener extends PhoneStateListener{<br />@Override<br />public void onCallStateChanged(int state, String incomingNumber) {<br />mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);<br />Log.v(this.getClass().getName(), "onCallStateChanged-state: " + state);<br />Log.v(this.getClass().getName(), "onCallStateChanged-incomingNumber: " + incomingNumber);<br />switch (state) {<br />case TelephonyManager.CALL_STATE_IDLE:<br />mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);<br />break;<br />case TelephonyManager.CALL_STATE_OFFHOOK:<br />//CALL_STATE_OFFHOOK;<br />break;<br />case TelephonyManager.CALL_STATE_RINGING:<br />if ("123456".equals(incomingNumber)){<br />//mTelephonyService.endCall();<br />endCall();<br />}else{<br />mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);<br />}<br />break;<br />default:<br />break;<br />}<br />super.onCallStateChanged(state, incomingNumber);<br />}<br />@Override<br />public void onDataConnectionStateChanged(int state) {<br />Log.v(this.getClass().getName(), "onDataConnectionStateChanged-state: " + state);<br />super.onDataConnectionStateChanged(state);<br />}<br />@Override<br />public void onDataConnectionStateChanged(int state, int networkType) {<br />Log.v(this.getClass().getName(), "onDataConnectionStateChanged-state: " + state);<br />Log.v(this.getClass().getName(), "onDataConnectionStateChanged-networkType: " + networkType);<br />super.onDataConnectionStateChanged(state, networkType);<br />}<br />@Override<br />public void onServiceStateChanged(ServiceState serviceState) {<br />Log.v(this.getClass().getName(), "onServiceStateChanged-ServiceState: " + serviceState);<br />super.onServiceStateChanged(serviceState);<br />}<br />@Override<br />public void onSignalStrengthChanged(int asu) {<br />Log.v(this.getClass().getName(), "onSignalStrengthChanged-asu: " + asu);<br />super.onSignalStrengthChanged(asu);<br />}<br />@Override<br />public void onSignalStrengthsChanged(SignalStrength signalStrength) {<br />Log.v(this.getClass().getName(), "onSignalStrengthsChanged-signalStrength: " + signalStrength);<br />super.onSignalStrengthsChanged(signalStrength);<br />}<br />}<br />}<br />
<?xml version="1.0" encoding="utf-8"?><br /><manifest xmlns:android="http://schemas.android.com/apk/res/android"<br />package="com.geolo.pcp.android" android:versionCode="1"<br />android:versionName="1.0"><br /><application android:icon="@drawable/icon" android:label="@string/app_name"><br /><activity android:name=".PhoneCallActivity" android:label="@string/app_name"><br /><intent-filter><br /><action android:name="android.intent.action.MAIN" /><br /><category android:name="android.intent.category.LAUNCHER" /><br /></intent-filter><br /></activity><br /></application><br /><uses-permission android:name="android.permission.READ_PHONE_STATE" /><br /><uses-permission android:name="android.permission.CALL_PHONE" /><br /><uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /><br /><uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission><br /><uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission><br /><uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission><br /></manifest>
原理請看:http://blog.csdn.net/GEOLO/archive/2010/12/21/6090264.aspx
項目源碼:http://download.csdn.net/source/2927291