Android 5.1中的Android语音通话

时间:2015-11-24 07:03:27

标签: android

我有一个用于制作,接收,结束和拒绝来电的android语音电话apk,它在低于5.0的Android版本中工作正常,接听电话不适用于版本5.0 及以上。制作,结束和拒绝通话工作正常。

这是我的代码,请检查它,我认为这会有所帮助..

 private BroadcastReceiver receiveCallReceiver = new BroadcastReceiver(){

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i(LOG_TAG,"Recieved receive call intent");

        String requestId = intent.getStringExtra("REQUEST_ID");
        Log.i(LOG_TAG,"Request id is:"+requestId);

        try {
             Thread.sleep(2000);
        }catch (InterruptedException e){
            //we don't want
        }

        if (telephonyManager.getCallState() == telephonyManager.CALL_STATE_RINGING){
            Log.i(LOG_TAG,"Phone is ringing");
            Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON);
            buttonDown.putExtra(Intent.EXTRA_KEY_EVENT,new KeyEvent(KeyEvent.ACTION_UP,KeyEvent.KEYCODE_HEADSETHOOK));
            context.sendOrderedBroadcast(buttonDown, "android.permission.CALL_PRIVILEGED");

            Log.i(LOG_TAG,"Received the call");
            sendResult(requestId, "PASS",0,null,null);
        }
        else{
             Log.i(LOG_TAG,"Phone is not ringing to accept call");
             sendResult(requestId,"FAIL",ErrorCodes.PHONE_RING_ERROR,"Phone is not ringing to accept call",null);

        }
    }
};

0 个答案:

没有答案