听传出短信或发件箱

编程入门 行业动态 更新时间:2024-10-21 18:41:45
本文介绍了听传出短信或发件箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我开发,将存储所有传入和传出的短信在SD卡上的文本文件的应用程序。

I am developing an application which will store all the incoming and outgoing sms in a text file in SD card.

我能听使用广播接收传入的消息。我发现很难听传出的短信。

I am able to listen incoming messages using broadcast receiver. I am finding it very difficult to listen to outgoing SMS.

我知道,在一定程度上,需要在发件箱或者发件箱内容观察员进行设置,但我不知道该怎么做。

I know to some extent that a content observer on the sent box or outbox needs to be set, but I don't know how to do it.

如何才能做到这一点?

推荐答案

基本上,你必须注册内容的观察者......是这样的:

Basically, you have to register a content observer... something like this:

ContentResolver contentResolver = context.getContentResolver(); contentResolver.registerContentObserver(Uri.parse("content://sms/out"),true, yourObserver);

yourObserver 是一个对象(新YourObserver(新处理器()))可能是这样的:

yourObserver is an object (new YourObserver(new Handler())) that could look like this:

class YourObserver extends ContentObserver { public YourObserver(Handler handler) { super(handler); } @Override public void onChange(boolean selfChange) { super.onChange(selfChange); // save the message to the SD card here } }

那么,究竟你明白了短信的内容?您必须使用光标:

// save the message to the SD card here Uri uriSMSURI = Uri.parse("content://sms/out"); Cursor cur = this.getContentResolver().query(uriSMSURI, null, null, null, null); // this will make it point to the first record, which is the last SMS sent cur.moveToNext(); String content = cur.getString(cur.getColumnIndex("body")); // use cur.getColumnNames() to get a list of all available columns... // each field that compounds a SMS is represented by a column (phone number, status, etc.) // then just save all data you want to the SDcard :)

更多推荐

听传出短信或发件箱

本文发布于:2023-11-12 12:02:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581450.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:短信   发件箱

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!