简体   繁体   English

Android NotificationCompat.Builder addPerson示例

[英]Android NotificationCompat.Builder addPerson example

I am looking for an example of the NotificationCompat.Builder's method addPerson. 我正在寻找NotificationCompat.Builder的方法addPerson的示例。

From the documentation I can see that I can either provide the contact's CONTENT_LOOKUP_URI or that the system can also resolve mailto: or tel: schemes. 文档中可以看到,我可以提供联系人的CONTENT_LOOKUP_URI,或者系统还可以解析mailto:tel:方案。

Given this, here is my test: 鉴于此,这是我的测试:

  • I created an Android P emulator 我创建了一个Android P模拟器
  • I added a contact to the contact provider (through the Contacts app) with an email address foo@bar.com 我通过电子邮件应用程序向联系人提供者添加了联系人(通过“联系人”应用程序),电子邮件地址为foo@bar.com。

Then I used mailto: scheme with the following code : 然后,我将mailto: scheme与以下代码结合使用:

private fun createNotification(contactEmail: String) {
        val mBuilder = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
                .setSmallIcon(R.drawable.ic_chat_black_24px)
                .setContentTitle("Contact found")
                .setContentText("Contact $contactEmail")
                .setShowWhen(true)
                .addPerson("mailto:$contactEmail")

        val mNotificationManager = NotificationManagerCompat.from(this)
        mNotificationManager.notify(1, mBuilder.build())

    }

The notification is well displayed but I cannot see the association with the contact or person. 通知显示良好,但我看不到与联系人或个人的关联。 How is it supposed to look like and how can I know if it worked ? 它看起来应该是什么样子,我怎么知道它是否起作用? As I cannot notice anything (even a log) I suppose that it does not work. 由于我什么都没注意到(甚至没有日志),因此我认为它不起作用。

Also, if you are not using the mailto: or tel: scheme, how are you supposed to retrieve the contact's CONTENT_LOOKUP_URI ? 另外,如果您不使用mailto:tel:方案,应该如何检索联系人的CONTENT_LOOKUP_URI

Any pointer or code sample would help. 任何指针或代码示例都将有所帮助。 Thanks ! 谢谢 !

The documentation states: "Depending on user preferences, this annotation may allow the notification to pass through interruption filters, and to appear more prominently in the user interface." 该文档指出:“根据用户的喜好,此注释可能允许通知通过中断过滤器,并在用户界面中更显眼地出现。” So I guess to test this feature you should go into your emulator settings -> sound -> Do not disturb here you see the exceptions. 因此,我想测试一下此功能,应该进入模拟器设置->声音->请勿打扰,您会在这里看到异常。 When in do not disturb mode, if the email address you are passing belongs to someone in the "exceptions" the notification will be displayed otherwise it won't. 在“请勿打扰”模式下,如果您传递的电子邮件地址属于“例外”中的某人,则将显示通知,否则不会显示。

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

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