简体   繁体   English

ShowCallLog Intent 在由“com.android.contacts”处理时不起作用

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

I am trying to open the call logs activity from my app using an intent and startActivity(ForResult).我正在尝试使用意图和 startActivity(ForResult) 从我的应用程序中打开通话记录活动。
It does work fine, except on some devices.它确实工作正常,除了在某些设备上。

After investigation, I noticed that when the intent resolve to this class :经过调查,我注意到当意图解决此 class 时

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

then startActivity (or startActivityForResult ) has "no effect" / the CallLogs is NOT displayed .然后startActivity (或startActivityForResult“无效”/不显示 CallLogs As per the name 'NonPhoneActivity', this makes sense I guess..根据名称“NonPhoneActivity”,我猜这是有道理的..

(info about this NonPhoneActivity activity: (有关此NonPhoneActivity活动的信息:
https://android.googlesource.com/platform/packages/apps/Contacts/+/master/AndroidManifest.xml ) 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 :这是代码(仅供参考,使用startActivityForResult ;我观察到与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!为什么呼叫日志意图解析为ComponentName("com.android.contacts", "com.android.contacts.NonPhoneActivity") ...即使在电话上!
    On emulator, the intent resolve to "com.android.dialer",com.android.dialer.main.impl.MainActivity" , which is able to display CallLogs.在模拟器上,意图解析为"com.android.dialer",com.android.dialer.main.impl.MainActivity" ,它能够显示 CallsLogs
  • 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?由于( "com.android.contacts", "com.android.contacts.NonPhoneActivity" )有时/通常是唯一能够处理Intent { act=android.intent.action.VIEW typ=vnd.android.cursor.dir/calls }的组件(*) Intent { act=android.intent.action.VIEW typ=vnd.android.cursor.dir/calls } ,我应该使用另一个意图(另一个动作)来显示呼叫日志吗?
    Which other Intent should I use to display CallLogs ?我应该使用哪个其他 Intent 来显示 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" * :根据结果PackageManager.queryIntentActivities(showCallLog, PackageManager.MATCH_ALL) ,这是一个只有一项的列表,即"com.android.contacts", "com.android.contacts.NonPhoneActivity"

Nailed it (almost):钉住它(几乎):

When Google Dialer (Google Phone) app is installed, the following intent action is available: com.android.phone.action.RECENT_CALLS :安装 Google Dialer (Google Phone) 应用后,可以使用以下意图操作: 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 应用在启动时显示“历史记录”/“最近通话”标签。

Google Phone's manifest excerpt: Google Phone 的清单摘录:

<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" />在清单中我们可以看到: <category android:name="android.intent.category.TAB" />
How could I use this to force Google Phone app to display the 'recent call' TAB?我如何使用它来强制 Google Phone 应用显示“最近通话”标签? 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).. (我知道,我们没有 Google Phone 应用程序的源代码,但是,希望他们使用一些(意图中 EXTRA 的标准系统/命名约定)..
Anyone?任何人?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 执行applyBatch时未找到权限com.android.contacts异常 - Authority com.android.contacts not found exception when doing applyBatch 如何打开com.android.contacts / .CallDetalActivity - how to open com.android.contacts/.CallDetalActivity 无法传递结果ResultInfo {who = null,request = 1,result = -1,data = Intent {dat = content://com.android.contacts/contacts/lookup…}} - Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.contacts/contacts/lookup…}} 传递结果失败 ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.contacts/contacts/lookup...}} - Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.contacts/contacts/lookup...}} 如何保存从com.android.contacts,Android中提取的图像? - How to save image extracted from com.android.contacts, Android? android 中 content://com.android.contacts 的用途是什么 - What is use of content://com.android.contacts in android android联系人源代码com.android.contacts - android contact source code com.android.contacts java.io.FileNotFoundException:content://com.android.contacts/contacts/24093/photo仅适用于旧照片 - java.io.FileNotFoundException: content://com.android.contacts/contacts/24093/photo for old photos only 使用什么代替Contacts.Intents.UI.LIST_STARRED_ACTION在com.android.contacts中显示已加星标的联系人? - What to use instead of Contacts.Intents.UI.LIST_STARRED_ACTION to display starred contacts in com.android.contacts? Adobe air内容:\\\\ com.android.contacts \\ display_photo \\加载照片 - Adobe air content:\\com.android.contacts\display_photo\ load a photo
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM