Android-Telephony application that keeps focus on incoming calls

筅森魡賤 提交于 2019-12-04 07:38:10
Jim

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

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

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