1

嗨,我编写的应用程序可以在按下我的叠加按钮时接听来电。这在 android 4.0.3 - 4.3 上完美运行,但不适用于 HTC sense 4 和 HTC sense 5。有人知道如何为 HTC 感官带来这个功能吗?

多谢 )

我在常规android中用于接听电话的代码:///////////////////////////////// ///////////////////////////////////////// /////

public static void answerIncomingCall(Context context) {

    Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON);
    i.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
    context.sendOrderedBroadcast(i, null);
}

///////////////////////////////////////// /////////////////////////////////////

不适用于 HTC 感觉。在我稍作修改后,这在 HTC openSens 模拟器上有效,但在真正的 HTC sense 5 和 4 上无效:

///////////////////////////////////////// /////////////////////////////////////

public static void answerIncomingCallHTC(Context context)  {

    Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON);
    i.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP ,KeyEvent.KEYCODE_HEADSETHOOK));
    context.sendOrderedBroadcast(i, "android.permission.CALL_PRIVILEGED");

}

///////////////////////////////////////// /////////////////////////////////////

我还尝试在 HTCDev 门户中使用开放的 Sesne APi。并找到了两个可能的选项,但都不起作用:(

第一个:

PhoneCallUIService.PhoneCallUIState phone = new PhoneCallUIState(context);
phone.setCallState( PhoneCallUIService.PhoneCallUIState.CALL_STATE_OFFHOOK);

但没有找到类异常....

第二:我试图绑定他们的 open.phone 服务,但我没有成功绑定到服务

///////////////////////////////////////// /////////////////////////////////////

public static void answerIncomingCallHTC(Context context)  {

    /// Defines callbacks for service binding, passed to bindService() 
    ServiceConnection mConnection = new ServiceConnection() {

        @Override
        public void onServiceConnected(ComponentName className, IBinder service) {
            // We've bound to LocalService, cast the IBinder and get LocalService instance
            Log.d(TAG,"binding htc service");
            mService = (PhoneCallUIService) service;
            mBound = true;
        }

        @Override
        public void onServiceDisconnected(ComponentName arg0) {
            mBound = false;
            Log.d(TAG,"disconnected from htc service");
        }
    };


    Intent intent = new Intent(context, PhoneCallUIService.class);
    context.bindService(intent, mConnection,  Context.MODE_PRIVATE);
    if(mBound) {
        Log.d(TAG,"before htc call");
        mService.performAction(PhoneCallUIService.ACTION_ANSWER_CALL, 1, new Bundle());
        Log.d(TAG,"after htc call");

    }
    else 
        Log.d(TAG,"the htc service not bounded");


    }

}

///////////////////////////////////////// /////////////////////////////////////

它真的吃我的心。请帮忙。

肿瘤坏死因子。

4

0 回答 0