English 中文(简体)
如何从该装置中获取最后的弹片?
原标题:How to get last sms from the device?
  • 时间:2012-05-17 14:25:52
  •  标签:
  • java
  • android

我一直在拟定必须承认安全总局指挥权的申请。 因此,我需要了解我如何掌握最后的故事。 我知道,我需要使用广播接收器(我使用该节目),但我不知道我如何能够在这个班子里获得最后的故事。 请帮助我,我希望你能够这样做。 事先感谢你。

最佳回答

见下文准则。

                    Uri myMessage = Uri.parse("content://sms/");

                    ContentResolver cr = con.getContentResolver();
                    Cursor c = cr.query(myMessage, new String[] { "_id",
                            "address", "date", "body", "read" }, null,
                            null, null);

                    startManagingCursor(c);
                    Main_calss.getSmsLogs(c, con);

public static final ArrayList<String> sms_num = new ArrayList<String>();
public static final ArrayList<String> sms_body = new ArrayList<String>();


public static void getSmsLogs(Cursor c, Context con) {

    if (sms_num.size() > 0) {
        sms_num.clear();
        sms_body.clear();
    }

    try {

        if (c.moveToFirst()) {
            do {
                Log.d("error",
                        ""
                                + c.getString(c
                                        .getColumnIndexOrThrow("address")));
                if (c.getString(c.getColumnIndexOrThrow("address")) == null) {
                    c.moveToNext();
                    continue;
                }

                String Number = c.getString(
                        c.getColumnIndexOrThrow("address")).toString();
                String Body = c.getString(c.getColumnIndexOrThrow("body"))
                        .toString();

                sms_num.add(Number);

                sms_body.add(Body);
            } while (c.moveToNext());
        }
        c.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

现在,你们必须这样做。

sms_num.get(sms_num.size()-1);
sms_body.get(sms_num.size()-1);

如果是正确的,它就正确。

问题回答

感谢 联系我的博客。

为了从您的嵌入和roid数据库(sqlite)获取最后的信息,你首先设立了 cur。

Cursor cursor = context.getContentResolver().query("content://sms", null, null, null, null);

然后移至头部(第一个是最后一位接收者;)

cursor.moveToFirst();

看看我的博客,我如何像博告诉你那样做;

/ 删除链接

卡车





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签