如何注册SMS数据库的变化? [英] How to register for SMS database changes?

查看:262
本文介绍了如何注册SMS数据库的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何注册SMS数据库的变化?

How can I register for SMS database changes?

我想:

mCursor = mActivity.getContentResolver().query(Sms.CONTENT_URI, new String[] {
           Sms.ADDRESS
   }, null, null, null);
mCursor.registerDataSetObserver(mydataSetObserver);

在这里mydataSetObserver是这样实现的:

where mydataSetObserver is implemented like this:

 private class MyDataSetObserver extends DataSetObserver {
       public void onChanged() {
           System.out.println ("1");
       }
       public void onInvalidated() {
            System.out.println ("2");
       }
}

但是,当我试图发送一个SMS消息在模拟器中, MyDataSetObserver永远不会被调用。

But when I tried sending a SMS message in the emulator, MyDataSetObserver never get called.

你能告诉我为什么?

感谢你。

推荐答案

这听起来像你正在试图做的是要进行更改设备上的SMS数据库的能力。

It sounds like all you are trying to do is have the ability to make changes to the SMS database on the device.

就是我在过去做的是通过使用标签在AndroidManifest.xml。应用程序I提出使用READ_SMS权限以及READ_CONTACTS所需的权限,但是获得许可写入数据库将被以相同的方式进行。

The way I have done it in the past is by using tags in the AndroidManifest.xml. The application I made needed to use the READ_SMS permission as well as the READ_CONTACTS permission, however gaining permission for writing to the database would be done in the same way.

我定义在AndroidManifest.xml这些所需的权限与下面的标记文件:     

I defined these desired permissions in the AndroidManifest.xml file with the following tag:

包括在许可的列表可以使用的WRITE_SMS,这应该给你所需要的能力。

Included in the list of permissions you can use is WRITE_SMS, which should give you the desired capability.

请注意:因为我是一个新用户,计算器只会让我发布一个超链接的这个职位,我试着包括了很多详细信息,但是无法做到这一点。请到了Android开发者网站和搜索AndroidManifest.xml文件,并看到更多的信息,如果需要的话。

Please note: because I am a new user, StackOverflow would only let me post one hyperlink for this post, I tried including alot more information however was unable to do so. Please go to the android developer website and search for the AndroidManifest.xml file and see more info if need be.

这篇关于如何注册SMS数据库的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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