如果电话(本机)中存在多个未读的SMS,如何通知从本机(电话)读取了哪个SMS? [英] How to get notify which SMS got read from native(phone) if multiple unread SMS are present in phone(native)?

查看:57
本文介绍了如果电话(本机)中存在多个未读的SMS,如何通知从本机(电话)读取了哪个SMS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果本机(电话)中有3条未读的SMS消息,并且用户已阅读其中一条SMS.如何识别在我们的应用程序中从本地读取了哪些SMS.

当前,我正在使用ContentObserver,当用户从native(phone)读取SMS时,将调用onChange()方法.

我能够收到所有未读的SMS消息:

 光标游标= this.getContentResolver().query(Uri.parse("content://sms/"),null,"read = 0",null,null); 

如何识别从本地(电话)读取的SMS.任何帮助或指导将不胜感激.

在Nexus 4(Android 4.3)-API 18中,如果在Android Native Sms Client中针对两个未读SMS(属于两个不同的发件人)的通知(在设备状态栏中),则用户单击该通知onChange(context,uri))在我的应用中被调用,在其中我试图获取读取的SMS的ID:

 字符串id = uri.getLastPathSegment(); 

对于上述情况,出现了作为"id"值的收件箱".但是,如果要由用户从Android Native Sms Client中读取任何SMS,则不会调用onChange(context,uri)方法.

在Samsung Galaxy S3(Android 4.1.2-API 16)中,在任何一种情况下都不会调用onChange(context,uri)(即,如果用户从本机读取SMS或用户单击通知,设备状态栏),用于Android Native Sms Client中的两个未读SMS(属于两个不同的发件人).

(在API 16中,当调用以本机方式接收的新SMS时,调用onChange(context,uri)且"id"的值等于该SMS的唯一ID-在Nexus 4(Android 4.3)上进行了测试)

注意:此处,来自本机"是指来自设备的默认SMS客户端".

解决方案

要确定哪个消息已从未读变为已读,您可能必须在自己的数据结构中跟踪所有未读消息的状态,并在每个过程中进行比较您的内容查看器检测到onChange以确定哪个/是否有任何消息更改了读取状态.您可以通过在Content Resolver查询中包括其他投影和选择参数来将数据范围缩小到仅关注字段的方式来提高性能.

希望即将到来的Google承诺对Android 4.4中的SMS API进行更改,这将使隐藏的API和内容提供程序的使用对于实现此类目标而言是不必要的.

您还可以通过查找

How to identify which SMS got read from native(phone). Any help or guidance will be well appreciated.

In Nexus 4(Android 4.3) - API 18), If notification(in device status bar) for two unread SMS(belongs two different sender) in Android Native Sms Client, user clicks on that notification, onChange(context, uri) is called in my aaplication, inside it I have tried to get id of the read SMS:

String id = uri.getLastPathSegment();

For above mentioned case, "inbox" as value of "id" came. But for reading any of the SMS by user from in Android Native Sms Client, onChange(context, uri) method is not invoked.

In Samsung Galaxy S3(Android 4.1.2 - API 16), onChange(context, uri) is not at all invoked in either of the case (i.e. if user read the SMS from Native or user clicks on the notification(in device status bar) for two unread SMS(belongs two different sender) in Android Native Sms Client.

(In API 16, when new SMS received in native, onChange(context, uri) is called and value of "id" is equal to the unique ID for that SMS - Tested on Nexus 4(Android 4.3))

Note: Here, "from native" means "from the device's default SMS client".

解决方案

To determine definitely which message has changed from unread to read, you will likely have to track the state of all unread messages in your own data structure and compare during each onChange detected by your Content Observer to determine which/if any messages changed read states. You may able to improve performance by including additional projection and selection arguments in the Content Resolver queries to narrow the data set to only the fields of interest.

Hopefully, the upcoming changes to the SMS APIs that Google is promising in Android 4.4 will make the use of hidden APIs and Content Providers unnecessary for these sorts of purposes moving forward.

You may also be able to determine the SMS that was read (or at least the thread) by looking for the markAsRead debug message that is generated by the com.android.mms.data.Conversation class used by the native Messaging app:

D/Mms (1645): [192] markAsRead: update read/seen for thread uri: content://mms-sms/conversations/4

However, that may not always be reliable and would not work on Android 4.1+ devices unless your app has system privileges due to the restrictions placed on the READ_LOGS permission in API Level 16.

这篇关于如果电话(本机)中存在多个未读的SMS,如何通知从本机(电话)读取了哪个SMS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆