Aidl挂接电话-创新互联
ITelephony.aidl
当前名称:Aidl挂接电话-创新互联
文章源于:http://ybzwz.com/article/cdeiee.html
package com.android.internal.telephony;
interface ITelephony {
void answerRingCall();
boolean endCall();
}
MyPhoneService
创新互联于2013年开始,是专业互联网技术服务公司,拥有项目网站设计、成都做网站网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元湛江做网站,已为上家服务,为湛江各地企业和个人服务,联系电话:18982081108public 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 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://ybzwz.com/article/cdeiee.html