ShowCallLog Intent not working when handled by "com.android.contacts"

Viewed 45

I am trying to open the call logs activity from my app using an intent and startActivity(ForResult).
It does work fine, except on some devices.

After investigation, I noticed that when the intent resolve to this class:

ComponentName("com.android.contacts", "com.android.contacts.NonPhoneActivity")

then startActivity (or startActivityForResult) has "no effect" / the CallLogs is NOT displayed. As per the name 'NonPhoneActivity', this makes sense I guess..

(info about this NonPhoneActivity activity :
https://android.googlesource.com/platform/packages/apps/Contacts/+/master/AndroidManifest.xml )

Here is the code (FYI, with startActivityForResult; I observe the same behavior with startActivity:

additionalButtonsBinding.phoneSelectContactFragmentButtonsMissedCallButton.setOnClickListener(v -> {
    Intent showCallLog = new Intent();
    showCallLog.setAction(Intent.ACTION_VIEW); // "android.intent.action.VIEW"
    showCallLog.setType(CallLog.Calls.CONTENT_TYPE); // "vnd.android.cursor.dir/calls" 
    showCallLogLauncher.launch(showCallLog);
});
showCallLogLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
    new ActivityResultCallback<ActivityResult>() {
        @Override
        public void onActivityResult(ActivityResult result) {
            // result is always {resultCode=RESULT_CANCELED, data=null}
            // may the CallLogs be shown OR not
            // so startActivityForResult is useless: just here fore investigation purpose and completeness of my question
            Log.d(TAG, result.toString());
        }
    });

Questions:

  • Why does the CallLogs intent resolve to ComponentName("com.android.contacts", "com.android.contacts.NonPhoneActivity")... even on a Phone!
    On emulator, the intent resolve to "com.android.dialer",com.android.dialer.main.impl.MainActivity", which is able to display CallLogs.
  • Since ("com.android.contacts", "com.android.contacts.NonPhoneActivity") is sometimes/often the only component (*) able to handle Intent { act=android.intent.action.VIEW typ=vnd.android.cursor.dir/calls } , should I use another intent (another action) to display CallLogs?
    Which other Intent should I use to display CallLogs?

*: as per result PackageManager.queryIntentActivities(showCallLog, PackageManager.MATCH_ALL) , which is a list with only one item, being "com.android.contacts", "com.android.contacts.NonPhoneActivity"

1 Answers

Nailed it (almost):

When Google Dialer (Google Phone) app is installed, the following intent action is available: com.android.phone.action.RECENT_CALLS:

Intent googleDialerShowRecent = new Intent("com.android.phone.action.RECENT_CALLS");
if (BaseApplication.getInstance().getPackageManager().queryIntentActivities(googleDialerShowRecent, PackageManager.MATCH_ALL).size() > 0) {
    showCallLogLauncher.launch(googleDialerShowRecent);
}

I just do not knwo how to force the Google Phone app to display the 'History'/'Recent calls' tab on launch.

Google Phone's manifest excerpt:

<activity
    android:name="com.android.dialer.main.impl.MainActivity"
...>
    <intent-filter android:label="@ref/0x7f150123">
        <action android:name="com.android.phone.action.RECENT_CALLS" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.TAB" />  TAB HERE - Could I send some EXTRA in INTENT to force Google Dialer to display the 'recent call' TAB?
    </intent-filter>

Question:

In manifest we can see this: <category android:name="android.intent.category.TAB" />
How could I use this to force Google Phone app to display the 'recent call' TAB? Adding some EXTRA in the Intent? which one?
(I know, we do not have source code of Google Phone app, but, hopefully they use some (standard system / naming convention for EXTRAs in Intent)..
Anyone?

Related