なんとか切断までこぎつけたのでメモ。
もっと無駄を省ける気はしている。
あとエラー処理もかいてません。
実機(SO-01B:1.6)で確認済み
別途ITelephony.aidlを追加する事
—
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import com.android.internal.telephony.ITelephony;
import android.telephony.*;
public class MainActivity extends Activity {
private TelephonyManager m_telephonyManager;
private ITelephony m_telephonyService;
private PhoneStateListener m_phoneStateListener;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
m_telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Class<?> serviceManagerClass = maybeForName(“android.os.ServiceManager”);
if (serviceManagerClass == null) {
System.out.println(“serviceManagerClass==null;”);
}
Method getServiceMethod = maybeGetMethod(serviceManagerClass, “getService”, String.class);
if (getServiceMethod == null) {
System.out.println(“getServiceMethod==null;”);
}
Object telephonyService=invoke(getServiceMethod, null, Context.TELEPHONY_SERVICE);
if (telephonyService == null) {
System.out.println(“telephonyService==null;”);
}
m_telephonyService = ITelephony.Stub.asInterface((IBinder)telephonyService);
try {
m_telephonyService.endCall();
} catch (RemoteException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}
private static Class<?> maybeForName(String name) {
try {
return Class.forName(name);
} catch (ClassNotFoundException cnfe) {
// OK
return null;
} catch (RuntimeException re) {
return null;
}
}
private static Method maybeGetMethod(Class<?> clazz, String name, Class<?>… argClasses) {
try {
return clazz.getMethod(name, argClasses);
} catch (NoSuchMethodException nsme) {
// OK
return null;
} catch (RuntimeException re) {
return null;
}
}
private static Object invoke(Method method, Object instance, Object… args) {
try {
return method.invoke(instance, args);
} catch (IllegalAccessException e) {
return null;
} catch (InvocationTargetException e) {
return null;
} catch (RuntimeException re) {
return null;
}
}
}
—