启动具有时间限制的新活动

时间:2013-05-07 14:27:31

标签: android android-activity start-activity

我正在尝试启动具有时间限制的Android呼叫电话活动(Intent.ACTION_CALL)(活动仅在有限的时间内工作,例如仅10秒)。有没有办法做或者我必须创建自己的通话活动?

//溶液 我的解决方案是创建具有呼出接收器的服务,如http://www.codeproject.com/Articles/548416/Detecting-incoming-and-outgoing-phone-calls-on-And

在接收器中我有方法

try {
        String serviceManagerName = "android.os.ServiceManager";
        String serviceManagerNativeName = "android.os.ServiceManagerNative";
        String telephonyName = "com.android.internal.telephony.ITelephony";

        Class<?> telephonyClass;
        Class<?> telephonyStubClass;
        Class<?> serviceManagerClass;
        Class<?> serviceManagerNativeClass;
        Method telephonyEndCall;
        // Method getService;
        Object telephonyObject;
        Object serviceManagerObject;

        telephonyClass = Class.forName(telephonyName);
        telephonyStubClass = telephonyClass.getClasses()[0];
        serviceManagerClass = Class.forName(serviceManagerName);
        serviceManagerNativeClass = Class.forName(serviceManagerNativeName);

        Method getService = // getDefaults[29];
                serviceManagerClass.getMethod("getService", String.class);

        Method tempInterfaceMethod = serviceManagerNativeClass.getMethod(
                "asInterface", IBinder.class);

        Binder tmpBinder = new Binder();
        tmpBinder.attachInterface(null, "fake");

        serviceManagerObject = tempInterfaceMethod.invoke(null, tmpBinder);
        IBinder retbinder = (IBinder) getService.invoke(serviceManagerObject, "phone");
        Method serviceMethod = telephonyStubClass.getMethod("asInterface", IBinder.class);

        telephonyObject = serviceMethod.invoke(null, retbinder);
        telephonyEndCall = telephonyClass.getMethod("endCall");

        telephonyEndCall.invoke(telephonyObject);

    } catch (Exception e) {
        e.printStackTrace();
}

1 个答案:

答案 0 :(得分:2)

您应该使用闹钟并使用telephonyService.endCall()结束通话