有没有解决方案在活动中加载电话留言?

时间:2014-02-07 07:21:51

标签: android android-activity message

我想在我activity的手机中加载邮件。我搜索解决方案,但我找不到。

1 个答案:

答案 0 :(得分:2)

使用此:

private String SmsDetails(Application mContext) {
        // TODO Auto-generated method stub
        smsInbox = new ArrayList<Entry>();

        final Uri SMS_Inbox = Uri.parse("content://sms/inbox");
        String smsHistory = "";

        try {

            String sDirection = "1";
            String sMessageType = "0";
            String SMS_READ_COLUMN = "read";
            String SORT_ORDER = " _id ASC";
            int count = 0;
            Cursor cursor;
            int iLastIDRun = 0;

            // "address = '+9180009'"

            cursor = mContext.getContentResolver().query(
                    SMS_Inbox,
                    new String[] { "_id", "thread_id", "address", "person",
                     "date", "body" },
                     " _id > " + String.valueOf(iLastIDRun), null,
                    SORT_ORDER);
            sMessageType = "1";
            if (cursor != null) {
                try {

                    if (cursor.moveToFirst()) {
                        do {
                            String address = cursor.getString(2);
                            long timestamp = cursor.getLong(4);
                            String sBody = cursor.getString(5);

                            if (address.startsWith("1")) {
                                address = address.substring(1);
                            }

                            //store the required details



                        } while (cursor.moveToNext());

                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                cursor.close();

            }

            doCheckSmsHistory();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return smsHistory;

    }