如何在 Android 中以编程方式从设备读取 SMS 消息? [英] How can I read SMS messages from the device programmatically in Android?
本文介绍了如何在 Android 中以编程方式从设备读取 SMS 消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从设备中检索短信并显示它们?
I want to retrieve the SMS messages from the device and display them?
推荐答案
使用 Content Resolver ("content://sms/inbox") 读取收件箱中的短信.
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 中以编程方式从设备读取 SMS 消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文