5

I am developing a custom telephony application that is able to receive calls. Using this code for handling the incoming call https://code.google.com/p/auto-answer/source/browse/trunk/src/com/everysoft/autoanswer/AutoAnswerIntentService.java

Unfortunately my app loses focus on the incoming call.

THIS was a partial solution for outgoing calls Android- Telephone app that keeps focus on outgoing & incoming phoneCall

What about incoming calls? How do I keep focus in my custom app?

I am guessing this might involve downloading and modifying the source code as simply accessing the SDK gives little control over the built-in phone application.

Community
  • 1
  • 1
Bachalo
  • 6,965
  • 27
  • 95
  • 189
  • 1
    Please post the relevant code here, not just a link. – Bill the Lizard Jan 11 '14 at 16:28
  • the entire source library? – Bachalo Jan 11 '14 at 21:28
  • The link that I posted is somewhat irrelevant since any approach to answer calls (that I've tried)implementing only the Application Layer results in the native phone application obtaining focus. Hence my investigation of the source code @ https://android.googlesource.com – Bachalo Jan 11 '14 at 21:43
  • 2
    You should post the relevant parts of the code, or an example of how you're using the library. Enough to reproduce the problem. – Bill the Lizard Jan 12 '14 at 00:52
  • Perhaps another way of rephrasing my question is how do I modify the AOSP to achieve the aforementioned result? ( keeping the incoming calls screen from taking focus) – Bachalo Jan 12 '14 at 21:52

2 Answers2

1

Since the reference you made about outgoing calls is acceptable, then you can place an activity in front of the incoming call screen shortly after it displays. The difficulty in doing this is that the call state will change to "RINGING" and then also "OFFHOOK" but the phone has not displayed the InCallScreen when these are broadcast.

Like the post you referenced, this solution does not actually embed the phone feature into the app (like a webview for web browsing) but rather places an activity in front of the InCallScreen shortly after it displays.

For incoming calls, you need to delay the launch of your activity, like in this post:

Android - Customised New Incoming Call Screen

You can put anything on the screen at the point, the hard part is determining the lag time so that it meets your needs (slow enough so that the InCallScreen has a chance to launch but fast enough to be minimally disruptive).

Beyond that, even extending AOSP will not help unless you have access to each physical device where this will be used to root them or put a custom build on them. Access to the PhoneApp features is not accessible to non-system apps (the com.android.phone package).

Community
  • 1
  • 1
Jim
  • 10,172
  • 1
  • 27
  • 36
  • Thanks. In my case I am lucky in so far as I only have to target a single device , the Nexus5. Also, I am running a single application in 'kiosk mode'. Doesn't ActivityManager in AOSP control the stacking of new activities, such as the incoming call screen? – Bachalo Jan 17 '14 at 16:03
  • Yes you could poll for the InCallScreen activity to know when it is active to improve confidence that your screen is on top of it (http://stackoverflow.com/questions/18115493/android-dynamicly-get-the-current-activity-in-foreground) Or do you want to try to use reflection to modify / prevent InCallScreen from showing? ActivityManager calls using reflection will only work if you sign your app with the platform key. In other words, it only works on a custom Android build. – Jim Jan 17 '14 at 16:25
0

Mention the below broadcast receiver in manifest.xml file.

<receiver android:name="com.example.incomingcall.IncomingCallReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.PHONE_STATE" />
        </intent-filter>
</receiver>

IncomingCallReceiver.java:

public class IncomingCallReceiver extends BroadcastReceiver{

      public void onReceive(Context context, Intent intent) {
          Bundle extras = intent.getExtras();
          if (extras != null) {
          String state = extras.getString(TelephonyManager.EXTRA_STATE);
          if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
           Thread thread = new Thread(){
            private int sleepTime = 400;

        @Override
        public void run() {
         super.run();
        try {
                int wait_Time = 0;

                while (wait_Time < sleepTime ) {
                    sleep(100);
                    wait_Time += 100;
                }
            }catch (Exception e) {
                Toast.makeText(context,
                        "Error Occured Because:" + e.getMessage(),
                        Toast.LENGTH_SHORT).show();
            }
          context.startActivity(new Intent(context,CustomActivity.class)
                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        }
    };
    thread.run();

     }
   }
 }
}
user543
  • 3,623
  • 2
  • 16
  • 14
  • Thanks, I will try but I've tried many almost identical state based solutions with TelephonyManager and they did NOT have the intended effect. The call answer screen was still visible. Nexus 5 rooted running KitKat. I am almost 100% sure the actual AOSP must be hacked. – Bachalo Jan 16 '14 at 13:49
  • Actually "android.intent.action.NEW_OUTGOING_CALL" is ordered broadcast. So, by giving highest priority to intent filter(which is having highest priority that broadcast will fire first) we can launch our app. But "android.intent.action.PHONE_STATE" is unordered broadcast. So,priority is not useful. All will fire at the same time. So, I think it is not possible for incoming calls. – user543 Jan 17 '14 at 09:11