简体   繁体   English

如何获取我从应用程序发出的呼叫的通话结束通知-Android

[英]How to get a call ended notification for a call which i have placed from my application - Android

I am writing an application that gives a dialog(dialog which is an activity) for every international outgoing call. 我正在编写一个应用程序,该应用程序为每个国际拨出电话提供一个对话框(对话是一项活动)。 the application interrupts the outgoing call and gives an alert for all the international calls. 该应用程序会中断拨出电话并为所有国际电话发出警报。 On the users confirmation, a new call with the same number is placed. 在用户确认后,将放置一个具有相同号码的新呼叫。

My app is very similar to this one Outgoing call don't start 我的应用程序与此呼叫非常相似, 无法开始

However my broadcast receiver receives even the outgoing call i place from my application, this leads to an infinite loop. 但是我的广播接收器甚至接收到我从应用程序发出的去电,这导致了无限循环。 I am using the below code to disable the broadcast receiver after the call is placed from my app. 从我的应用发出呼叫后,我正在使用以下代码禁用广播接收器。

private void makeCall1(String number)  {
    PackageManager pm = mContext.getPackageManager();
     ComponentName componentName = new ComponentName(mContext,OutgoingCallReceiver.class);
   pm.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
   Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(number));
startActivity(callIntent);
  // Now wait for the call to end somehow and afterwards ->
  // pm.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
 }

How can i retrieve the call ended notification of the call that was placed by me so that i can write some code to enable the broadcast receiver for the future calls. 我如何检索由我发出的呼叫的通话结束通知,以便我可以编写一些代码以使广播接收器能够以后使用。

You need add a variable to control it...when the BroadCastReceiver is called first( ie this would be when the user places call and not from your app)then set the variable to true...Now if true only then show the dialog and later set the variable to false when the call is disconnected. 您需要添加一个变量来对其进行控制...首先调用BroadCastReceiver时(即,这是用户而非您的应用发出呼叫时),然后将该变量设置为true ...现在,如果为true,则仅显示对话框然后在通话中断时将变量设置为false。

Now how to know the call has ended? 现在如何知道通话已结束?

You can know the call has disconnected using states of call. 您可以使用通话状态知道通话已断开。

These are the states when the call is placed- 这些是拨打电话时的状态-

CALL_STATE_OFFHOOK->CALL_STATE_IDLE

CALL_STATE_OFFHOOK --> Called when the call is placed CALL_STATE_IDLE -----> Called when the call is disconnected CALL_STATE_OFFHOOK >拨打电话时呼叫CALL_STATE_IDLE ----->通话断开时呼叫

Now you want to know when the call has disconnected, you can set a variable to control it in your BroadCastReceiver 现在,您想知道呼叫何时断开,可以在BroadCastReceiver设置一个变量来控制它

private static boolean isCalled=false; 
  ................
  ................
     @Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
String state = bundle.getString(TelephonyManager.EXTRA_STATE);
  if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
     isCalled= true;
     Log.v("ranjapp", "Within DIALED NUMBER");
    } else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE) && isCalled){
         Log.v("ranjapp", "Within IDLE");
      //ADD YOUR CODE FOR WHAT NEEDS TO BE DONE AT CALL DISCONNECT
         isCalled=false;
 }
 .........................
 .........................

Also dont forget to add the permission in manifest as below: 同样不要忘记在清单中添加权限,如下所示:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从我的Android应用程序调用另一个应用程序(我没有源代码) - how to call another apllication(for which i dont have source code) from my android application 我创建了一个类来检测呼叫是否结束。 如果调用结束,如何在我的主方法中获取布尔值? - I created a class to detect that a call is ended. How is it possible to get in my main method the boolean value if call is ended? 每当我没有从应用程序android拨打电话时,每次结束电话都回到我的活动 - everytime End phone Call come back to my activity even if i have not make a phone call from my application android 通话时来自“我的应用程序”的通知声音 - Notification sound from My Application when in call 如何在Android应用程序中显示来电通知 - How to show incoming call notification in android application 如何收到Android中收到的通知的回电? - How do I get a call back for notification received in android? 如何在通话结束时调用/启动应用程序? - How to Invoke/Start an application when a call is ended? 如何从我的Android应用程序调用默认电子邮件应用程序 - How to call default email application from my android application 当我放置的方法是活动时,如何从片段活动中调用方法? - How can I call a method from fragment activity when my method placed is the Activity? 如何获得从某个应用程序卸载android应用程序的回电 - How to get a call back on uninstalling android application from ones application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM