繁体   English   中英

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

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

我正在尝试使用意图和 startActivity(ForResult) 从我的应用程序中打开通话记录活动。
它确实工作正常,除了在某些设备上。

经过调查,我注意到当意图解决此 class 时

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

然后startActivity (或startActivityForResult“无效”/不显示 CallLogs 根据名称“NonPhoneActivity”,我猜这是有道理的..

(有关此NonPhoneActivity活动的信息:
https://android.googlesource.com/platform/packages/apps/Contacts/+/master/AndroidManifest.xml

这是代码(仅供参考,使用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());
        }
    });

问题:

  • 为什么呼叫日志意图解析为ComponentName("com.android.contacts", "com.android.contacts.NonPhoneActivity") ...即使在电话上!
    在模拟器上,意图解析为"com.android.dialer",com.android.dialer.main.impl.MainActivity" ,它能够显示 CallsLogs
  • 由于( "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 } ,我应该使用另一个意图(另一个动作)来显示呼叫日志吗?
    我应该使用哪个其他 Intent 来显示 CallLogs

* :根据结果PackageManager.queryIntentActivities(showCallLog, PackageManager.MATCH_ALL) ,这是一个只有一项的列表,即"com.android.contacts", "com.android.contacts.NonPhoneActivity"

钉住它(几乎):

安装 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);
}

我只是不知道如何强制 Google Phone 应用在启动时显示“历史记录”/“最近通话”标签。

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>

问题:

在清单中我们可以看到: <category android:name="android.intent.category.TAB" />
我如何使用它来强制 Google Phone 应用显示“最近通话”标签? 在意图中添加一些额外的? 哪一个?
(我知道,我们没有 Google Phone 应用程序的源代码,但是,希望他们使用一些(意图中 EXTRA 的标准系统/命名约定)..
任何人?

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM