package com.android.internal.telephony;
interface ITelephony {
void answerRingCall();
boolean endCall();
}
MyPhoneService
public class MyPhoneService extends Service {
TelephonyManager manager;
ITelephony telephony;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
run();
return super.onStartCommand(intent, flags, startId);
}
private void run() {
manager= (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// 獲取類類型 Class<TelephonyManager> clazz = TelephonyManager.class;
try {
// 通過方法名和參數找到方法 Method method = clazz.getDeclaredMethod("getITelephony", null);
// 將此方法設為可用 method.setAccessible(true);
// 執行該方法 telephony = (ITelephony) method.invoke(manager, null);
}catch (NoSuchMethodException e) {
e.printStackTrace();
}catch (IllegalArgumentException e) {
e.printStackTrace();
}catch (IllegalAccessException e) {
e.printStackTrace();
}catch (InvocationTargetException e) {
e.printStackTrace();
}
// 設置電話狀態監聽 PhoneStateListener listener = new MyPhoneStateListener();
manager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
}
class MyPhoneStateListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_OFFHOOK:// 當摘機時 Log.i("onCallStateChanged", "CALL_STATE_OFFHOOK"
+ incomingNumber);
try {
telephony.endCall();
}catch (RemoteException e) {
e.printStackTrace();
}
break;
case TelephonyManager.CALL_STATE_RINGING:// 當響鈴時 Log.i("onCallStateChanged", "CALL_STATE_RINGING"
+ incomingNumber);
try {
// 接電話 telephony.answerRingCall();
}catch (RemoteException e) {
e.printStackTrace();
}
break;
case TelephonyManager.CALL_STATE_IDLE: // 當空閑時 Log.i("onCallStateChanged", "CALL_STATE_IDLE" + incomingNumber);
break;
default:
break;
}
super.onCallStateChanged(state, incomingNumber);
}
}
}
當前名稱:Aidl掛接電話-創新互聯
網站地址:http://vcdvsql.cn/article44/cdeiee.html
成都網站建設公司_創新互聯,為您提供網站維護、軟件開發、全網營銷推廣、網站設計公司、外貿建站、品牌網站制作
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯