检索Android中设备的所有收件箱消息 [英] Retrieve all inbox messages of device in android

查看:99
本文介绍了检索Android中设备的所有收件箱消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码.

Object[] pduArray = (Object[]) intent.getExtras().get("pdus"); 

SmsMessage[] messages = new SmsMessage[pduArray.length]; 

StringBuilder messageText = new StringBuilder();

for (int i = 0; i < pduArray.length; i++) {                 
     messages[i] = SmsMessage.createFromPdu((byte[])pduArray [i]);              
     messageText.append(messages[i].getMessageBody());          
} 

但是此代码仅适用于在设备中接收到短信的情况,但我需要检索所有收件箱中保存在android设备中的邮件,我该怎么办?

But this code is for only intimate when sms is received in a device but my need is to retrieve all inbox messages which is saved in android device in android how can I do it?

推荐答案

尝试以下代码:

   Uri SMSURI = Uri.parse("content://sms/inbox");
   String[] projection = new String[]{"_id", "address", "body", "date"};
   Cursor cursor = null;

   try {
        cursor = getContentResolver().query(SMSURI
                , projection
                , null //selection
                , null //selectionArgs
                , null); //sortOrder

        if (cursor != null && cursor.moveToFirst()) {
            do {
                int    id    = cursor.getInt(cursor.getColumnIndex("_id"));
                String address = cursor.getString(cursor.getColumnIndex("address"));
                String body = cursor.getString(cursor.getColumnIndex("body"));
                String date = cursor.getString(cursor.getColumnIndex("date"));

                Toast.makeText(getBaseContext(), "Message is >>"+body, 
                            Toast.LENGTH_SHORT).show();
                }

            } while (cursor.moveToNext());
        }

    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

这篇关于检索Android中设备的所有收件箱消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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