How to use the dialer while still viewing application information?

89 views Asked by At

Situation: Users of my application need to call their contacts and still being able to view special contact information.

Initiating a call is easy with the following code:

private void performDial(String numberString) {
    if ( checkSelfPermission(android.Manifest.permission.CALL_PHONE) == 
 PackageManager.PERMISSION_GRANTED) {
    if (!numberString.equals("")) {
            Uri number = Uri.parse("tel:" + numberString);
            Intent dial = new Intent(Intent.ACTION_CALL, number);
            startActivity(dial);
        }
   }
}

However the GUI of the dialer will hide the contact information. In order to view this contact information a user has to perform two steps:

  1. Push the home button This will shrink the dialer to a small “icon”.
  2. Use the left button to select the correct application in the list of running apps. Showing the relevant information while still having the dialer active in the form of the “icon”.

Questions:

Is it possible to start the dialer intent in the “icon” form?

Is it possible to perform the two steps programmatically?

What I tried already: The Intent parameters Flags and Extras, don’t seem to give options to start the dialer in the “icon” form.

The following code fragment emulates a home button:

Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);

And the following fragment could bring the main application back in front.

Intent intent = new Intent(this, MainActivity.class);
intent. addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | 
Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);

However both fragments won’t work after the dialer is active. And the dialer will not start if these fragments are executed directly after starting the intent.

Here is the manifest file:

<?xml version="1.0" encoding="utf-8"?>
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="copec.test2app">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".ShowWebsite"> </activity>
    <receiver android:name="copec.test2app.OutCallLogger" >
        <intent-filter>
            <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
        </intent-filter>
    </receiver>

</application>

Any help is appreciated.

1

There are 1 answers

4
David Wasser On BEST ANSWER

You can't hide the dialer. What you can do is to move your app to the foreground on top of the dialer. After launching the dialer with startActivity() you should wait until the call is intiated. You can do that by monitoring the outgoing call state, or just by simply waiting a few seconds (which you can do by wrapping the following code in a Runnable and then posting it to Handler using postDelayed(). Then, to move your app to the foreground, do this:

PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("your.package.name"); 
getApplicationContext().startActivity(intent);