如何以编程方式在android中接收离线短信

时间:2011-09-08 07:12:03

标签: android sms offline-mode

如果我的Android设备已关闭,那时有人正在向我的手机发送短信。 一旦我打开,我想通过编程方式获得短信。

这可能吗?

1 个答案:

答案 0 :(得分:0)

您可以像这样从收件箱中提取短信:

Uri mSmsinboxQueryUri = Uri.parse("content://sms/inbox");
        Cursor cursor1 = getContentResolver().query(mSmsinboxQueryUri,
                    new String[] { "_id", "thread_id", "address", "person", "date",
                                    "body", "type" }, null, null, null);
        startManagingCursor(cursor1);
        String[] columns = new String[] { "address", "person", "date", "body","type" };
        if (cursor1.getCount() > 0) {
            String count = Integer.toString(cursor1.getCount());
            Log.e("Count",count);
            while (cursor1.moveToNext()){
                String address = cursor1.getString(cursor1.getColumnIndex(columns[0]));
                String name = cursor1.getString(cursor1.getColumnIndex(columns[1]));
                String date = cursor1.getString(cursor1.getColumnIndex(columns[2]));
                String msg = cursor1.getString(cursor1.getColumnIndex(columns[3]));
                String type = cursor1.getString(cursor1.getColumnIndex(columns[4]));
            }
        }