android – 如何访问我在收件箱中收到的短信时间?

前端之家收集整理的这篇文章主要介绍了android – 如何访问我在收件箱中收到的短信时间?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我可以从收件箱中读取消息: –
  1. Uri uriSMSURI = Uri.parse("content://sms/inBox");
  2.  
  3. Cursor cur = getContentResolver().query(uriSMSURI,null,null);

我从这里访问日期: –

  1. date = cur.getString(cur.getColumnIndexOrThrow("date"));

但现在问题是它从收件箱中提供当前时间而不是消息时间.
对不起编辑错误&任何想法将不胜感激.
提前致谢!

解决方法

使用此代码
  1. ContentResolver contentResolver = getContentResolver();
  2. Cursor cursor = contentResolver.query( Uri.parse( "content://sms/inBox" ),null);
  3. cursor.moveToFirst();
  4. String date = cursor.getString(cursor.getColumnIndex("date"));
  5. Long timestamp = Long.parseLong(date);
  6. Calendar calendar = Calendar.getInstance();
  7. calendar.setTimeInMillis(timestamp);
  8. Date finaldate = calendar.getTime();
  9. String smsDate = finaldate.toString();
  10. Log.d(Home.class.getName(),smsDate);

猜你在找的Android相关文章