【问题标题】:How to disconnect a outgoing call programatically如何以编程方式断开拨出电话
【发布时间】:2012-04-03 04:26:38
【问题描述】:

我已使用以下代码以编程方式断开呼叫,但它不起作用。

private void callDisconnect(){ 
    try{ 
        TelephonyManager manager = (TelephonyManager)this.getSystemService(this.TELEPHONY_SERVICE); 
        Class c = Class.forName(manager.getClass().getName()); 
        Method m = c.getDeclaredMethod("getITelephony"); 
        m.setAccessible(true); 
        ITelephony telephony = (ITelephony)m.invoke(manager); 
        telephony.endcall(); 
    } catch(Exception e){ 
        Log.d("",e.getMessage()); 
    } 
}

有人可以帮我吗?我需要更改代码还是什么...??

【问题讨论】:

    标签: android


    【解决方案1】:

    要以编程方式断开呼叫,您必须在项目中添加ITelephony.AIDL 文件。如果你已经添加了它,那么你的包名必须是com/android/internal/telephony/ITelephony.AIDL:有关更多信息,请参阅Blocking Incoming call。从here 下载 AIDL 文件。

    要断开呼叫,请使用 ITelephony 的 endCall(); 方法

    【讨论】:

      【解决方案2】:

      只需使用此广播接收器。我在我的一个应用程序中对其进行了测试,它运行良好。

      public class MyBroadcastReceiver extends BroadcastReceiver
      {
      
          @Override
          public void onReceive(Context context, final Intent intent)
          {
      
      
              if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL))
              {
                  String phoneNumber = intent.getExtras().getString(Intent.EXTRA_PHONE_NUMBER);
      
                  if (phoneNumber.equals("123456"))
                  {
                      if (getResultData() != null)
                      {
      
                          setResultData(null);
                      }
      
      
                  }
      
              }
      
      
          }
      
      }
      

      【讨论】:

        【解决方案3】:

        在较新版本的 android 中不再可能。如果呼叫已经开始,用户决定何时结束呼叫。但是,您可以阻止呼叫发生。

        【讨论】:

          【解决方案4】:

          您可以使用广播接收器的 onReceive 方法中的 setResultData(null) 函数来阻止呼出。

          公共类 BlockOutgoing 扩展 BroadcastReceiver {

          String number;
          @Override
          public void onReceive(Context context, Intent intent) 
          {
              Log.d("12280", "asdasNumber is-->> " + number);
              number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
              setResultData(null);
              Toast.makeText(context, "Outgoing Call Blocked" , 5000).show();
          }
          

          }

             <receiver
                  android:name=".BlockOutgoing"
                  android:label="@string/app_name" >
                  <intent-filter android:priority="1">
          
                      <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
          
                  </intent-filter>
              </receiver>
          

          【讨论】:

            【解决方案5】:

            您无法在 android 2.3+ 中结束这样的通话...使用您的代码...我认为只有用户可以结束他的通话...对于早期版本 You can see this link This one

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2014-09-12
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多