重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

Aidl挂接电话-创新互联

ITelephony.aidlAidl挂接电话
package com.android.internal.telephony;

interface ITelephony {
void answerRingCall();
boolean endCall();
}

MyPhoneService

创新互联于2013年开始,是专业互联网技术服务公司,拥有项目网站设计、成都做网站网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元湛江做网站,已为上家服务,为湛江各地企业和个人服务,联系电话:18982081108
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 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://cqcxhl.cn/article/cdeiee.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP