3

I am doing verification call from my app.Which should disconnect after 5-10 seconds which is configured.

Here is my code;

                    Intent callIntent = new Intent(Intent.ACTION_CALL);
                    callIntent.setData(Uri.parse("tel:" + phoneNumber));
                    callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                    handler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                   /*It is never called up untill call got disconnected/hanged up. */
                            Log.d(TAG, "Disconnecting :");
                            disconnectCall();
                        }
                    }, 5000);

                    startActivity(callIntent);

The problem is disconnectCall() method not called until callIntent activity is suspended i.e user forcefully disconnected call/hanged up. I need to parrelly invoke disconnectCall() during call activity.Not getting where is the problem in code.

Madhukar Hebbar
  • 3,113
  • 5
  • 41
  • 69

3 Answers3

3

You are calling startActivity(callIntent). This means you are transferring control to the caller app android. The call can now disconnected by android caller application when user wants.

Danial Hussain
  • 2,488
  • 18
  • 38
2

As daniel mentioned, once you started call activity you are no longer in control and your application main thread will only get CPU time when your activity is back on foreground.

to hang up use this.

Community
  • 1
  • 1
Ofek Ron
  • 8,354
  • 13
  • 55
  • 103
1

From my point of perspective the problem is with the single threaded android service class which is not invoking handler or any methods until previous activity get over.So i added piece of code inside handler runnable and it got worked.

 handler.post(callTestHandler = new Runnable() {
                        @Override
                        public void run() {
                            try {
                                //Intent callIntent = new Intent("android.intent.action.NEW_OUTGOING_CALL");
                                Intent callIntent = new Intent(Intent.ACTION_CALL);
                                callIntent.setData(Uri.parse("tel:" + phoneNumber));
                                callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                handler.postDelayed(new Runnable() {
                                    @Override
                                    public void run() {
                                        Log.d(TAG, "Disconnecting :");
                                        disconnectCall();
                                    }
                                }, 5000);
                                startActivity(callIntent);
                            } catch (Exception e) {
                                e.getMessage();
                            }
                        }
                    });

If anyone has different answer/solution please post it.

Madhukar Hebbar
  • 3,113
  • 5
  • 41
  • 69