gpt4 book ai didi

Android Intent 过滤器问题

转载 作者:搜寻专家 更新时间:2023-11-01 08:13:55 24 4
gpt4 key购买 nike

我正在尝试编写一个 Intent 过滤器以从联系人列表中选择一个联系人(纯粹出于教育目的......我正在学习 Intent )。在隐式 Intent 上调用 startActivity 后,android 应该找到我的自定义 Activity 以及默认 Activity 作为候选 Activity ,并让我选择我想使用的 Activity ( Intent 解析)。

但是,根据我当前的设置,它会打开 android 的默认联系人选择器,但我没有选择。这是我的 Intent 过滤器。

<activity android:name=".ContactPicker" android:label="PICKER" >
<intent-filter>
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="content" android:host="com.android.contacts" android:path="contacts" />
</intent-filter>
</activity>

下面是我如何调用主要 Activity 的隐式 Intent :

Intent intent = new Intent(Intent.ACTION_PICK, Uri.parse("content://com.android.contacts/contacts"));
startActivityForResult(intent, PICK_CONTACT);

最佳答案

尝试:

<intent-filter>
<action android:name="android.intent.action.PICK"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="vnd.android.cursor.dir/contact"/>
</intent-filter>

关于Android Intent 过滤器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6802082/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com