2017-01-31 3 views
0

私は着信を処理して取り消したり答えたりしましたが、できません。 IはXamarin:ACTION_ANSWERの対処方法

[BroadcastReceiver(Label = "Blocking Calls")] 
[IntentFilter(new string[] { "android.intent.action.PHONE_STATE" })] 
public class MyReceiver : Android.Content.BroadcastReceiver 
{ 
    private const string IntentAction_BlockingCalls = "android.intent.action.PHONE_STATE"; 

    public override void OnReceive(Context context, Intent intent) 
    { 
     if (intent.Action == IntentAction_BlockingCalls) 
     { 
      // ensure there is information 
      if (intent.Extras != null) 
      { 
       // get the incoming call state 
       string state = intent.GetStringExtra(TelephonyManager.ExtraState); 

       // check the current state 
       if (state == TelephonyManager.ExtraStateRinging) 
       { 
        // read the incoming call telephone number 
        string telephoneNumber = intent.GetStringExtra(TelephonyManager.ExtraIncomingNumber); 

        Intent buttonDown = new Intent(Intent.ActionMediaButton); 
        buttonDown.PutExtra(Intent.ActionView, new KeyEvent(KeyEventActions.Down, Keycode.Headsethook)); 
        context.SendBroadcast(buttonDown); 

        Toast.MakeText(context, telephoneNumber, ToastLength.Short).Show(); // Flag 4   
        // check the read telephone 
        if (string.IsNullOrEmpty(telephoneNumber)) 
         telephoneNumber = string.Empty; 
       } 
       else if (state == TelephonyManager.ExtraStateOffhook) 
       { 
        // Toast.MakeText(context, "The call is answered", ToastLength.Short).Show(); // Flag 5 
        // incoming call answer 
       } 
       else if (state == TelephonyManager.ExtraStateIdle) 
       { 
        // Toast.MakeText(context, "The call have ended", ToastLength.Short).Show(); // Flag 6 
        // incoming call end 
       } 
      } 
     } 
    } 
} 

私は正常着信電話番号を取得するコードのその部分を使用するが、私は答えまたはit.Soを取り消すことができない、私は下にそのアクション(ActionAnswer)を使用しようとした

Intent A = new Intent(Intent.ActionAnswer); 

アンドロイドデベロッパーサイトのこのスクリーンショットに表示されているように、 image 出力と入力は何もありません! どうすれば対応できますか?または私は着信コールをキャンセルするために使用できる他の方法がありますか? アドバイスありがとうございます。 ここにアンドロイドデベロッパーのリンクがあります。 https://developer.android.com/reference/android/content/Intent.html#ACTION_ANSWER

+0

何をしようとしていますか?それは、人々に、より多くの文脈を与えるはずです。 –

+0

何をしようとしていますか?着信を処理するために使用されるアクション。インテントアクティビティをコードで呼び出そうとしていますか? –

+0

さて、質問の本文を修正しました。 – mostafayasin

答えて

0

最後に、私は解決策を見つけ、それは私とうまく動作します。 それが私たちが必要とする部分です。

// check the current state 
       if (state == TelephonyManager.ExtraStateRinging) 
       { 
        // read the incoming call telephone number 
        string telephoneNumber = intent.GetStringExtra(TelephonyManager.ExtraIncomingNumber); 

        // You can use Endswith, Equals, or any other available methods 
        //if (telephoneNumber.EndsWith("604")) 
        if (telephoneNumber.Equals("01282790604")) 
        { 
         var manager = (TelephonyManager)context.GetSystemService(Context.TelephonyService); 

         IntPtr TelephonyManager_getITelephony = JNIEnv.GetMethodID(
           manager.Class.Handle, 
           "getITelephony", 
           "()Lcom/android/internal/telephony/ITelephony;"); 

         IntPtr telephony = JNIEnv.CallObjectMethod(manager.Handle, TelephonyManager_getITelephony); 
         IntPtr ITelephony_class = JNIEnv.GetObjectClass(telephony); 
         IntPtr ITelephony_endCall = JNIEnv.GetMethodID(
           ITelephony_class, 
           "endCall", 
           "()Z"); 
         JNIEnv.CallBooleanMethod(telephony, ITelephony_endCall); 
         JNIEnv.DeleteLocalRef(telephony); 
         JNIEnv.DeleteLocalRef(ITelephony_class); 


         Toast.MakeText(context, telephoneNumber + "Is Blocked", ToastLength.Long).Show(); 
        } 
関連する問題