It feels like this question has been asked allot, but non of them fits my needs an non of the solutions work for me.
I have an application with a class extending to PhoneStateListener to listen for the following states:
- CALL_STATE_RINGING (Here I set a global string variable with the incoming Phone Number)
- CALL_STATE_OFFHOOK (Here I want to move my Task/Process to the Front for the user to see my application with the callers details on the screen, and not the In Call screen)
I need a way to minimize the In Call Screen (into the Notifications Area) I know it can be done (have Proof) but I do not know how to do it After it is minimized, I should be able to move my task to the front which was previously moved to the back.
My application starts up, the user logs in and by keep pressing the back button, the user stays logged in but the application is moved to the background. If an incoming call occurs, I want to see if the callers phone number exists in my application (The application keeps a couple of users info), then go to the users info after the In Call Screen is minimized.
When I run this code in the CALL_STATE_OFFHOOK state, the call is minimized and the Map Loads on Full Screen (The Proof)
public String IncomingTelephoneNumber;
private class CallStateListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING: {
IncomingTelephoneNumber = incomingNumber;
break;
}
case TelephonyManager.CALL_STATE_OFFHOOK: {
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
activity.startActivity(intent);
break;
}
}
}
}
It is not possible to get hold of the Maps Source Code. In the same way I want to do this, but with my own application, I Tried this, but does not work, the In Call Screen is still in front of the application (or the application isn't called at all). The code does not break or anything, it is just that my app does not come forward.
public String IncomingTelephoneNumber;
private class CallStateListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING: {
IncomingTelephoneNumber = incomingNumber;
break;
}
case TelephonyManager.CALL_STATE_OFFHOOK: {
try {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags(270532608);//This is the flag which is used from the Launcher, LogCat helped here //flg=0x10200000
intent.setClassName(activity.getPackageName(), Splash.class.getCanonicalName());
activity.startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
break;
}
}
}
}
I have tried other ways to bring the application back to the front, but does not work.
I saw this post, but no solution what so ever.
I use Android Version 10 as it is required by the devices being used (Samsung P-1000 Tablets, Android 2.3.3 is the latest official version)
Any help would be much appreciated. It may be a train smash or something very simple which needs to be called. But I would like this to be done, the same way as the maps do it.
EDIT: I came across a solution to minimize the In Call Screen (Not the best Solution, but it works)
public String IncomingTelephoneNumber;
private class CallStateListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING: {
IncomingTelephoneNumber = incomingNumber;
break;
}
case TelephonyManager.CALL_STATE_OFFHOOK: {
try {
//This will simulate pressing the Home button
//Thus Minimizing the In Call Screen
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(startMain);
//This is the part still not working Correctly
//Moving my Task/Process to the Front for the user to see
//This is Android 10, I still can not find a solution to move task to front
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName(activity, Splash.class.getCanonicalName());
activity.startActivity(intent);
} catch (Exception e) {
Log.v("", "e: " + e.getMessage());
e.printStackTrace();
}
break;
}
}
}
}