Move the Default Incoming Calling Screen to Background on TelephonyManager.CALL_STATE_RINGING in Android
Asked Answered
D

1

7

I am working on an application in which I have to override the INCOMING CALL SCREEN.

When device receives a call, I have to show a popup of my application. I have done a detailed research about this task. CALL POPOUT is an application which is using the same functionality, but I am not getting the source code.

Currently I am having few modules by which we can get the action of INCOMING CALL.

public class MyPhonestateListner extends PhoneStateListener {
    Context context;
    List<String> blockedNumberList = new ArrayList<String>();
    BlockDataSource datasourceobj;

    public MyPhonestateListner(Context context) {
        super();
        this.context = context;

    }

    @Override
    public void onCallStateChanged(int state, String callingNumber) {
        super.onCallStateChanged(state, callingNumber);
        callingNumber = callingNumber.replace(" ", "");
        switch (state) {

        case TelephonyManager.CALL_STATE_IDLE:
            break;

        case TelephonyManager.CALL_STATE_OFFHOOK:
            // handle out going call
            // if(blockedNumberList.contains(callingNumber))
            endCallIfBlocked(callingNumber);
            break;

        case TelephonyManager.CALL_STATE_RINGING:
            // handle in coming call
             new Handler().postDelayed(new Runnable() {
                  public void run() {
                      Intent intentPhoneCall = new Intent("android.intent.action.CALL");
                              intentPhoneCall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  context.startActivity(intentPhoneCall);
                          }
                     }, 10);
            // if(blockedNumberList.contains(callingNumber))
            //endCallIfBlocked(callingNumber);
            // ActivityManagerNative.getDefault().moveTaskToBack(i);
            //android.app.ActivityManager.RunningTaskInfo runningtaskinfo = TaskUtil.getPresentTaskInfo(this);
            break;

        default:
            break;
        }
    }


}


MY reciever

public class BlockReciever extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        System.out.println("I am reciever");
        TelephonyManager telephony = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        MyPhonestateListner listener = new MyPhonestateListner(context);
        telephony.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
    }
}

With the help of above code, I am getting the MAP screen of my Application on TOP of CALL SCREEN, but JUST FOR FEW MICRO SECONDS and then the INCOMING CALL SCREEN comes on the top. I HAVE TO HIDE THE CALL SCREEN when device receives any call and need to show the screen of my application.

Please suggest.

Dressmaker answered 17/12, 2014 at 11:29 Comment(1)
Hey @Sam-In-TechValens, did you manage to solve this one in the end?Sourdough
I
0

When there is incoming call, both your activity and the default incoming activity will show. In case your activity show first, then later the incoming activity will show over yours, it's tasks and back stack stuff.

The solution: when your activity is showing then check if the incoming activity display over yours --> move your activity on top again, except user dismiss your activity.

Please see my answer to the similar question here

Inextinguishable answered 12/5, 2016 at 0:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.