我使用Itelephony
服務以編程方式結束通話。它的工作對HTC的Android 4.1版本,但不工作的SAMSUNG GT-S7562
一個ndroid version 4.0.4
這裏是我的代碼電話服務結束通話()不工作三星GT-S7562安卓版本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): [email protected]58
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" />
my Itelepho ny.aidl文件
package com.android.internal.telephony;
interface ITelephony {
boolean endCall();
void answerRingingCall();
}
這是一個雙SIM卡設備,所以它沒有使用標準的「TelephonyManager」。你可以看到它在日誌中使用'MSimTelephonyManager'類(這顯然適用於多SIM設備)。您需要進一步挖掘以查看'MSimTelephonyManager'中的可用方法 –
嘗試使用反射來訪問該設備上的getITelephonyMSim()方法。 –