Android-Telephony application that keeps focus on incoming calls

眉间皱痕 提交于 2019-12-09 18:27:33

问题


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.


回答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).




回答2:


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();

     }
   }
 }
}


来源:https://stackoverflow.com/questions/21008264/android-telephony-application-that-keeps-focus-on-incoming-calls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!