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 handleIntent { 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"