如何从以编程方式在Android的收件箱读取短信? [英] How can I read SMS messages from the inbox programmatically in Android?
本文介绍了如何从以编程方式在Android的收件箱读取短信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要检索从收件箱中的短信并显示出来?
I want to retrieve the SMS messages from the inbox and display them?
推荐答案
使用内容解析器(的内容://短信/收件箱)。阅读短信这是在收件箱
Use Content Resolver ("content://sms/inbox") to read SMS which are in inbox.
// public static final String INBOX = "content://sms/inbox";
// public static final String SENT = "content://sms/sent";
// public static final String DRAFT = "content://sms/draft";
Cursor cursor = getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);
if (cursor.moveToFirst()) { // must check the result to prevent exception
do {
String msgData = "";
for(int idx=0;idx<cursor.getColumnCount();idx++)
{
msgData += " " + cursor.getColumnName(idx) + ":" + cursor.getString(idx);
}
// use msgData
} while (cursor.moveToNext());
} else {
// empty box, no SMS
}
请添加 READ_SMS 许可。
我希望它可以帮助:)
这篇关于如何从以编程方式在Android的收件箱读取短信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文