本文介绍了搜索短信收件箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何搜索的短信收件箱,并显示最新的消息来自一个特殊的数字。例如搜索该号码收到999999999,并显示最后一条消息。是没有办法做到这一点?

我用这个code到返回的邮件数我的收件箱

  TextView的视图;

@覆盖
公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);

  鉴于=(TextView中)findViewById(R.id.textView1);

  最后乌里SMS_INBOX = Uri.parse(内容://短信/收件箱);
  光标C = getContentResolver()查询(SMS_INBOX,NULL,NULL,NULL,NULL);
  INT unreadMessagesCount = c.getCount();
  c.deactivate();

  view.setText(将String.valueOf(unreadMessagesCount));
 

解决方案

如果你只想要一个特定号码发送的最后一条消息使用这样的:

 最后乌里SMS_INBOX = Uri.parse(内容://短信/收件箱);
光标光标= getContentResolver()查询(SMS_INBOX,空,地址=?,
        新的String [] {9999999999},日期递减限制1);
如果(cursor.moveToFirst()){
    // 做一点事
    Log.v(榜样,cursor.getString(cursor.getColumnIndex(身体)));
}
cursor.close();
 

第二个答案来在安卓短信相关的有多少数据库列?是在不同的列有很大的参考短信。

How can I search the sms inbox and show latest message from a special number. For example search for "999999999" and show last message received from this number. Is any way to do this?

I have use this code to return the count of messages my inbox

TextView view;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

  view = (TextView) findViewById(R.id.textView1);

  final Uri SMS_INBOX = Uri.parse("content://sms/inbox");
  Cursor c = getContentResolver().query(SMS_INBOX, null, null, null, null);
  int unreadMessagesCount = c.getCount();
  c.deactivate();

  view.setText(String.valueOf(unreadMessagesCount));
解决方案

If you only want the last message sent by a specific number use this:

final Uri SMS_INBOX = Uri.parse("content://sms/inbox");
Cursor cursor = getContentResolver().query(SMS_INBOX, null, "address = ?",
        new String[] {"9999999999"}, "date desc limit 1");
if(cursor.moveToFirst()) {
    // Do something
    Log.v("Example", cursor.getString(cursor.getColumnIndex("body")));
}
cursor.close();

The second answer to How many database columns associated with a SMS in android? is a great reference for different columns in an SMS.

这篇关于搜索短信收件箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 01:56