Answering calls programmatically

1,628 views
Skip to first unread message

flohier

unread,
Jul 17, 2009, 8:07:46 PM7/17/09
to android-platform
I'm trying to answer incoming calls automatically. I wrote the
following code with this goal:


try {
Intent intent = new Intent(Intent.ACTION_ANSWER);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP
| Intent.FLAG_DEBUG_LOG_RESOLUTION
| Intent.FLAG_FROM_BACKGROUND
| Intent.FLAG_ACTIVITY_NEW_TASK);/**/
intent.addCategory(Intent.CATEGORY_DEFAULT);
startActivity(intent);
}
catch (Exception e)
{
Context context = getApplicationContext();
Toast toast=Toast.makeText(context, e, 1);
toast.setGravity(Gravity.BOTTOM, 0, 0);
toast.show();
//cleanup();
return;
}


I get an activitynotfound exception. Is the Android dialer not
registering a receiver for android.intent.action.ANSWER ?

Thanks.

Jean-Baptiste Queru

unread,
Jul 17, 2009, 8:10:04 PM7/17/09
to android-...@googlegroups.com
What are you trying to achieve? This sounds scary...

You should be able to find the answer somewhere the source code.

JBQ
--
Jean-Baptiste M. "JBQ" Queru
Software Engineer, Android Open-Source Project, Google.

Questions sent directly to me that have no reason for being private
will likely get ignored or forwarded to a public forum with no further
warning.

flohier

unread,
Jul 17, 2009, 10:19:19 PM7/17/09
to android-platform
My grandma is blind and I would like the phone I gave her to
automatically accept incoming calls and even voice the person calling
in.

I've been dealing with this issue for quite some time now and I wish
there was a book called "Android Internals" :)

What part of the source code do you feel has the remedy ?

Thanks,
> warning.- Hide quoted text -
>
> - Show quoted text -

Jean-Baptiste Queru

unread,
Jul 17, 2009, 10:42:15 PM7/17/09
to android-...@googlegroups.com
The dialer is part of the Contacts app:
http://android.git.kernel.org/?p=platform/packages/apps/Contacts.git;a=summary

You'll probably need to play around with the Phone app itself (which
is the part responsible for actually handling the calls):
http://android.git.kernel.org/?p=platform/packages/apps/Phone.git;a=summary

I don't know how much you'll have to tweak those to achieve what you want.

JBQ

flohier

unread,
Jul 18, 2009, 11:10:24 PM7/18/09
to android-platform
Ok, looking at the default phone dialer activity, the manifest for the
default phone app shows the following:

<activity android:name="InCallScreen" android:theme="@android:style/
Theme.NoTitleBar" android:label="@string/phoneIconLabel"
android:excludeFromRecents="true" android:launchMode="singleInstance"
android:screenOrientation="nosensor" android:exported="false" />

I suppose that the android:exported="false" attribute means that the
in call screen is not available for external activities.

If this is true, I am confused about the Intent.ACTION_ANSWER intent
exposed by the SDK.

Can an application actually accept an incoming call without user
intervention ?

FL

On Jul 17, 7:42 pm, Jean-Baptiste Queru <j...@android.com> wrote:
> The dialer is part of the Contacts app:http://android.git.kernel.org/?p=platform/packages/apps/Contacts.git;...
>
> You'll probably need to play around with the Phone app itself (which
> is the part responsible for actually handling the calls):http://android.git.kernel.org/?p=platform/packages/apps/Phone.git;a=s...

Mark Murphy

unread,
Jul 19, 2009, 6:37:12 AM7/19/09
to android-...@googlegroups.com
flohier wrote:
> If this is true, I am confused about the Intent.ACTION_ANSWER intent
> exposed by the SDK.
>
> Can an application actually accept an incoming call without user
> intervention ?

At the SDK level, not that I am aware of.

At the firmware level, yes.

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Warescription: Three Android Books, Plus Updates, $35/Year

flohier

unread,
Jul 21, 2009, 9:42:27 PM7/21/09
to android-platform
Thanks Mark. 2 things:

- What is the purpose of ACTION_ANSWER then exposed by the SDK ?

- I'm still digging into the dialer source code. While its seems that
the InCallScreen activity does not export it's interface, it also
looks like the dialer has some code defined under the AIDL interface.
I'm not yet sure how these 2 interface differ. Again, all I am trying
to do is make sure that my activity accepts an incoming call.

Thanks for your help.

On Jul 19, 3:37 am, Mark Murphy <mmur...@commonsware.com> wrote:
> flohierwrote:
> > If this is true, I am confused about the Intent.ACTION_ANSWER intent
> > exposed by the SDK.
>
> > Can an application actually accept an incoming call without user
> > intervention ?
>
> At the SDK level, not that I am aware of.
>
> At the firmware level, yes.
>
> --
> Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy

Sam

unread,
Jul 22, 2009, 5:12:28 AM7/22/09
to android-platform
Seems that ACTION_ANSWER not working because it is not declared to be
handled in packages/apps/Phone.

However, u can answer call by invoking the "internal" API void
answerRingingCall() defined by ITelephony.aidl. Have to get the client
side proxy to that interface by ITelephony.Stub.asInterface
(ServiceManager.getService(Context.TELEPHONY_SERVICE)). This can be
used to temp work-around, as it is not recommended by Google (I
guess:)

Sam

flohier

unread,
Jul 24, 2009, 9:48:44 PM7/24/09
to android-platform
Thanks Sam.

Thanks to your guidance, I've been documenting myself on the aidl
concept and certainly still learning ...

In the kernel and framework, I don't see answerRingingCall the
function nor do I see the ITelephony.aidl definiiton.

Could you please suggest where to look ?

Thanks,

On Jul 22, 2:12 am, Sam <samuel.li...@gmail.com> wrote:
> Seems that ACTION_ANSWER not working because it is not declared to be
> handled in packages/apps/Phone.
>
> However, u can answer call by invoking the "internal" API void
> answerRingingCall() defined by ITelephony.aidl. Have to get the client
> side proxy to that interface by ITelephony.Stub.asInterface
> (ServiceManager.getService(Context.TELEPHONY_SERVICE)). This can be
> used to temp work-around, as it is not recommended by Google (I
> guess:)
>
> Sam
>
> On Jul 22, 9:42 am,flohier<floh...@gmail.com> wrote:
>
>
>
> > Thanks Mark. 2 things:
>
> > - What is the purpose of ACTION_ANSWER then exposed by the SDK ?
>
> > - I'm still digging into the dialer source code. While its seems that
> > the InCallScreen activity does not export it's interface, it also
> > looks like the dialer has some code defined under the AIDL interface.
> > I'm not yet sure how these 2 interface differ. Again, all I am trying
> > to do is make sure that my activity accepts an incoming call.
>
> > Thanks for your help.
>
> > On Jul 19, 3:37 am, Mark Murphy <mmur...@commonsware.com> wrote:
>
> > > flohierwrote:
> > > > If this is true, I am confused about the Intent.ACTION_ANSWER intent
> > > > exposed by the SDK.
>
> > > > Can an application actually accept an incoming call without user
> > > > intervention ?
>
> > > At the SDK level, not that I am aware of.
>
> > > At the firmware level, yes.
>
> > > --
> > > Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> > > Warescription: Three Android Books, Plus Updates, $35/Year- Hide quoted text -

flohier

unread,
Jul 27, 2009, 12:26:53 PM7/27/09
to android-platform
Ok. I've copied the ITelephony.aidl file in my project from the kernel
source.

The Service Manager is not exposed by the SDK so the following syntax
is rejected:


ITelephony sPhone=ITelephony.Stub.asInterface(ServiceManager.getService
(Context.TELEPHONY_SERVICE))

I've tried this:

sPhone = ITelephony.Stub.asInterface(getSystemService
(Context.TELEPHONY_SERVICE));

Which is not valid because asInterface expects an IBinder as opposed
to an object.

As you can tell, I'm fairly new to the AIDL concept ...

So my question how do I bind the stub to the telephony system
service ?

Thanks,
> > - Show quoted text -- Hide quoted text -
Reply all
Reply to author
Forward
Message has been deleted
0 new messages