Itelephony服务结束通话()不适用于三星GT-S7562 Android版4.0.4

时间:2013-10-09 04:02:12

标签: android telephony

我正在使用Itelephony服务以编程方式结束通话。它正在使用HTC android 4.1版但不适用于SAMSUNG GT-S7562ndroid version 4.0.4 这是我的代码

TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
            System.out.println("telephonyManager..."+telephonyManager);
            Class clazz = null;
            try {
                clazz = Class.forName(telephonyManager.getClass().getName());
                System.out.println("clazz..."+clazz);
            } catch (ClassNotFoundException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            Method method = null;
            try 
            {
                method = clazz.getDeclaredMethod("getITelephony");
                System.out.println("method..."+method);
            } catch (NoSuchMethodException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            method.setAccessible(true);
            ITelephony telephonyService = null;
            try 
            {
                telephonyService = (ITelephony) method.invoke(telephonyManager);
            } catch (IllegalArgumentException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (IllegalAccessException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (InvocationTargetException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            try
            {
                telephonyService.endCall();
                Intent   intent = new Intent(OutGoingScreen.this, Dialpad.class);
                startActivity(intent); 
            } catch (RemoteException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

我的日志显示

10-09 09:26:18.938: D/memalloc(4653): /dev/pmem: Mapped buffer base:0x51bf0000 size:9031680 offset:7495680 fd:68
10-09 09:26:19.038: I/System.out(4653): telephonyManager...android.telephony.MSimTelephonyManager@41aefa58
10-09 09:26:19.038: I/System.out(4653): clazz...class android.telephony.MSimTelephonyManager
10-09 09:26:19.038: W/System.err(4653): java.lang.NoSuchMethodException: getITelephony []
10-09 09:26:19.058: W/System.err(4653):     at java.lang.Class.getConstructorOrMethod(Class.java:460)
10-09 09:26:19.058: W/System.err(4653):     at java.lang.Class.getDeclaredMethod(Class.java:685)
10-09 09:26:19.058: W/System.err(4653):     at             com.example.demo.OutGoingScreen$1.onClick(OutGoingScreen.java:73)
10-09 09:26:19.058: W/System.err(4653):     at android.view.View.performClick(View.java:3567)
10-09 09:26:19.058: W/System.err(4653):     at android.view.View$PerformClick.run(View.java:14224)
10-09 09:26:19.058: W/System.err(4653):     at android.os.Handler.handleCallback(Handler.java:605)
10-09 09:26:19.058: W/System.err(4653):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-09 09:26:19.058: W/System.err(4653):     at android.os.Looper.loop(Looper.java:137)
10-09 09:26:19.058: W/System.err(4653):     at android.app.ActivityThread.main(ActivityThread.java:4517)
10-09 09:26:19.058: W/System.err(4653):     at java.lang.reflect.Method.invokeNative(Native Method)
10-09 09:26:19.068: W/System.err(4653):     at java.lang.reflect.Method.invoke(Method.java:511)
10-09 09:26:19.068: W/System.err(4653):     at    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
10-09 09:26:19.068: W/System.err(4653):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
10-09 09:26:19.068: W/System.err(4653):     at dalvik.system.NativeStart.main(Native Method)
10-09 09:26:19.068: D/AndroidRuntime(4653): Shutting down VM
10-09 09:26:19.078: W/dalvikvm(4653): threadid=1: thread exiting with uncaught exception (group=0x40c06a68)
10-09 09:26:19.088: E/AndroidRuntime(4653): java.lang.NullPointerException
10-09 09:26:19.088: E/AndroidRuntime(4653):     at com.example.demo.OutGoingScreen$1.onClick(OutGoingScreen.java:79)
10-09 09:26:19.088: E/AndroidRuntime(4653):     at android.view.View.performClick(View.java:3567)
10-09 09:26:19.088: E/AndroidRuntime(4653):     at android.view.View$PerformClick.run(View.java:14224)
10-09 09:26:19.088: E/AndroidRuntime(4653):     at android.os.Handler.handleCallback(Handler.java:605)
10-09 09:26:19.088: E/AndroidRuntime(4653):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-09 09:26:19.088: E/AndroidRuntime(4653):     at android.os.Looper.loop(Looper.java:137)
10-09 09:26:19.088: E/AndroidRuntime(4653):     at android.app.ActivityThread.main(ActivityThread.java:4517)
10-09 09:26:19.088: E/AndroidRuntime(4653):     at java.lang.reflect.Method.invokeNative(Native Method)
10-09 09:26:19.088: E/AndroidRuntime(4653):     at java.lang.reflect.Method.invoke(Method.java:511)
10-09 09:26:19.088: E/AndroidRuntime(4653):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
10-09 09:26:19.088: E/AndroidRuntime(4653):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
10-09 09:26:19.088: E/AndroidRuntime(4653):     at dalvik.system.NativeStart.main(Native Method)

我在清单

中添加了此内容
 <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
 <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
 <uses-permission android:name="android.permission.READ_CONTACTS" />
 <uses-permission android:name="android.permission.VIBRATE" />
 <uses-permission android:name="android.permission.CALL_PHONE" />
 <uses-permission android:name="android.permission.READ_PHONE_STATE" />
 <uses-permission android:name="android.permission.READ_CALL_LOG" />
 <uses-permission android:name="android.permission.WRITE_CONTACTS" />

我的Itelephony.aidl文件是

package com.android.internal.telephony;
interface ITelephony {

boolean endCall();

void answerRingingCall();

}

2 个答案:

答案 0 :(得分:1)

你好像在这里得到NoSuchMethodException

 method = clazz.getDeclaredMethod("getITelephony");

它可能是从samsumg设备中的android框架中删除该方法。你可以通过尝试该方法在android 4.0模拟器中运行来测试这个问题。

编辑:我刚检查了Android TelephonyManager.java here的源代码。该方法确实存在于android 4.0.4源代码中。对我来说,问题看起来像特定的samsumg设备。您可以在另一个运行android 4.0.4的实际设备中进行测试以进行验证。我的运行是4.3所以无法测试。

答案 1 :(得分:0)

三星设备的MSimTelephonyManager类可能与Code Aurora的代码有一些相似之处 -

https://github.com/gp-b2g/frameworks_base/blob/master/telephony/java/android/telephony/MSimTelephonyManager.java

除了使用getITelephonyMSim代替getITelephony获取电话接口之外,endcall接口下的ITelephonyMSim声明是boolean endCall(int subscription)因此您可能需要指定要挂断的呼叫的订阅ID。您项目中的aidl文件需要更改为ITelephonyMSim.aidl并进行相应调整。

https://github.com/gp-b2g/frameworks_base/blob/master/telephony/java/com/android/internal/telephony/ITelephonyMSim.aidl

另一种选择,假设MSimTelephonyManager扩展了Android的TelephonyManager(应该是代码的第一行中的强制转换没有抛出异常的情况),就是调用getSuperclass()首先获取TelephonyManager类(或使用Class.forName("android.telephony.TelephonyManager")直接获取它),然后调用原始getITelephony,但根据实现情况,这可能仅适用于默认订阅。