2

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.

Jelle
  • 67
  • 1
  • 5

1 Answers1

0

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);
David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • thanks for the responce, the application is moved to the foreground which is great. However the application is newly started, not moved to the foreground. Meaning the previous information is lost. by adding: intent. addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); It is working great. – Jelle Nov 30 '17 at 11:59
  • Sorry, that makes no sense. I think you may be seeing another bug. Please do the following to check: remove those 2 flags then install your app. Then kill your app using force stop in the settings. Then start your app normally by tapping the icon from the HOME screen. Then check and see if it works properly. Please post your results. – David Wasser Nov 30 '17 at 18:49
  • After performing the step you mentioned the app restarts the activity (in the debugger the oncreate is executed). WIth the 2 flags the oncreate is skipped and the app pop's in front. So it seems to work with the two flags but not without them. – Jelle Dec 01 '17 at 08:43
  • Hmmm. Im glad youve solved the problem but this still makes no sense. Can you please post your manifest? Just edit your post and add it to the origibal question. – David Wasser Dec 01 '17 at 09:29