2

I want to create an android app which will do the following

  1. Traps/listens to an incoming call event ( im aware this step may have duplicates on SO but for the sake of completeness, im asking)

  2. Takes over the control and hits a web service ( HTTP POST ) to get some info from the internet

  3. And display the same as an "alert widget" on top of a "call receive/reject buttons", usually a place where we get "face" of the contact.

basic question is , is it feasible to develop such an app on stock android ? if yes , how ? What are the consequences , if any ?

The solution should work on latest Android releases as well ( 2.3 onwards, 2.3 had a controversial patch which broke may apps relying on private telephony api of android )

http://developer.android.com/reference/android/content/BroadcastReceiver.html states that,

In particular, you may not show a dialog or bind to a service from within a BroadcastReceiver. For the former, you should instead use the NotificationManager API. For the latter, you can use Context.startService() to send a command to the service.

Reno
  • 33,594
  • 11
  • 89
  • 102
Rakesh Waghela
  • 2,227
  • 2
  • 26
  • 46

1 Answers1

0

For the 1) part you can create a BroadcastReceiver and listen for the

TelephonyManager#ACTION_PHONE_STATE_CHANGED action.

This will handle your call event.

For the 2) part to need to write an AsyncTask that performs the HttpPost action to your webservice. There are many tutorials available on the web on how to go about doing the HttpPost action.

Now, whenever you implement an AsyncTask, you have a onPostExecute method. Inside that method you can do your 3rd part of displaying using the Alert Dialog.

Hope it helps,

All the best

Cheers

Parth Doshi
  • 4,200
  • 15
  • 79
  • 129
  • Does it work with Android 2.3 ( and latest ) onwards ? I have gone through lot of SO debates and other on line materials which refers to a problematic patch on a private telephony api which allows only system apps to gain access to the kind of use case we have ? – Rakesh Waghela Dec 13 '11 at 19:24
  • Yes, your right Android 2.3 has certain issues. I found this question: http://stackoverflow.com/questions/4715250/how-to-grant-modify-phone-state-permission-for-apps-ran-on-gingerbread . But anyways you can try it on Android 2.2 first, till then the issues will be resolved :) – Parth Doshi Dec 14 '11 at 04:13