2016-12-30 151 views
0

我正在开发移动APP,我需要根据联系人组将呼入转移到不同的号码。我将我的联系人分组,每个组都有不同的呼叫转移号码。当我收到来电时,我应该转发它的群组。动态Android呼叫转移

我PhoneStateListener在Call_State_Ringing写了这个代码:

package com.example.user2.callforwardnew; 

import android.app.Activity; 
import android.content.Context; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.telephony.PhoneStateListener; 
import android.telephony.TelephonyManager; 
import android.util.Log; 
import android.widget.Toast; 


public class CallActivity extends Activity { 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    TelephonyManager telephonyManager = 
       (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); 

    PhoneStateListener callStateListener = new PhoneStateListener() { 
     public void onCallStateChanged(int state, String incomingNumber){ 
      if(state==TelephonyManager.CALL_STATE_RINGING){ 

       String url = "tel:" + "**21*" + "XXXXX" + Uri.encode("#"); 
       Intent intent1 = (new Intent(Intent.ACTION_CALL, Uri.parse(url))); 
       intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
       startActivity(intent1); 
      } 
      if(state==TelephonyManager.CALL_STATE_OFFHOOK){ 

       Toast.makeText(getApplicationContext(),"Phone is Currently in A call", 
         Toast.LENGTH_LONG).show(); 
      } 
      if(state==TelephonyManager.CALL_STATE_IDLE){ 



       Toast.makeText(getApplicationContext(),"phone is neither ringing nor in a call", 
         Toast.LENGTH_LONG).show(); 
      } 
     } 
    }; 
    telephonyManager.listen(callStateListener,PhoneStateListener.LISTEN_CALL_STATE); 
} 

}

的问题是:当第一个电话来了也不会转发它只是在电话呼叫转移登记XXXX号。那么第二个电话会在正确的时间转发。 的问题: 我如何转发来电根据来电显示

+0

_第一次来电时,它不会被转发,它只是在电话转接中注册xxxx号码。您能解释一下吗,这个不清楚 – AxelH

+0

第一:电话转接设置被禁用。 打开:设置>我的设备>呼叫>附加设置>呼叫转移>语音呼叫。 然后第一个电话会来,手机将测距,并没有呼叫转移。但是第一次来电后,电话转接设置将被启用,并且xxxx号码将被登记在电话呼叫转接设置中。 第二次收入电话会正确转发给xxxx。 –

+0

嗯,我猜你的意图是启用设置(不知道这个系统)。所以我认为这是逻辑。收到的电话已经收到,因此转发已经晚了。你可以尝试手动。 (不知道你可以改变设置将接到一个电话,但它probalby将不会被转发,如果它已经振铃) – AxelH

回答

0

这是我发现。 答案是:在我们的移动电话上收到呼叫后,我们无法进行呼叫转移 原因:由于呼叫转移是由网络提供商完成,而不是由您的设备完成。

流程: - 首先使用:MMI代码21向网络提供商请求呼叫转移。 - 网络提供商将在您的设备中注册您的请求并更改呼叫转移设置。 - 当新的呼叫网络提供商将直接转发它,并且没有任何内容会发送到您的设备。 as shown in this diagram