如何从 Messenger 获取短信日期?
How to get the SMS date from messenger?
Android默认信使使用接收时间(图片)将短信分成几组。
我正在尝试在自定义列表视图中显示短信收件箱,就像使用光标的默认信使一样:
// Create Inbox box URI
Uri inboxURI = Uri.parse( "content://sms/inbox" );
// List required columns
String[] reqCols = new String[]{"_id", "address", "body", "date"};
// Get Content Resolver object, which will deal with Content
// Provider
ContentResolver contentResolver = getContentResolver();
// Fetch Inbox SMS Message from Built-in Content Provider
Cursor cursor = contentResolver.query( inboxURI, reqCols, null, null,
null );
sms = new ArrayList<>();
String date = "";
cursor.moveToLast();
while (cursor.moveToPrevious() || cursor.isLast()) {
//to get phone number
address = cursor.getString( cursor.getColumnIndex( "address" ) );
//to get massage
body = cursor.getString( cursor.getColumnIndexOrThrow( "body" ) );
//to get date of sms
date = cursor.getString( cursor.getColumnIndexOrThrow( "date" ) );
Long timestamp = Long.parseLong( date );
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis( timestamp );
Date finalDate = calendar.getTime();
smsDate = finalDate.toString();
但它不像 that.It 那样工作,也不像 "Sun Aug 12 07:13:13 ....."。我想显示与默认信使相同的时间。解决方法是什么?
在 Sms 表中,日期以毫秒为单位存储为 INTEGER。所以,使用
long sms_time= cur.getLong(cur.getColumnIndexOrThrow("date")) on Cursor.
这是收到短信的时间(以毫秒为单位)。现在获取以毫秒为单位的当前时间。
long now = System.currentTimeMillis();//get Current Time
现在计算 M=分钟差:
long minutes=(now - sms_time)/(1000*60);
来源:
Android默认信使使用接收时间(图片)将短信分成几组。
我正在尝试在自定义列表视图中显示短信收件箱,就像使用光标的默认信使一样:
// Create Inbox box URI
Uri inboxURI = Uri.parse( "content://sms/inbox" );
// List required columns
String[] reqCols = new String[]{"_id", "address", "body", "date"};
// Get Content Resolver object, which will deal with Content
// Provider
ContentResolver contentResolver = getContentResolver();
// Fetch Inbox SMS Message from Built-in Content Provider
Cursor cursor = contentResolver.query( inboxURI, reqCols, null, null,
null );
sms = new ArrayList<>();
String date = "";
cursor.moveToLast();
while (cursor.moveToPrevious() || cursor.isLast()) {
//to get phone number
address = cursor.getString( cursor.getColumnIndex( "address" ) );
//to get massage
body = cursor.getString( cursor.getColumnIndexOrThrow( "body" ) );
//to get date of sms
date = cursor.getString( cursor.getColumnIndexOrThrow( "date" ) );
Long timestamp = Long.parseLong( date );
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis( timestamp );
Date finalDate = calendar.getTime();
smsDate = finalDate.toString();
但它不像 that.It 那样工作,也不像 "Sun Aug 12 07:13:13 ....."。我想显示与默认信使相同的时间。解决方法是什么?
在 Sms 表中,日期以毫秒为单位存储为 INTEGER。所以,使用
long sms_time= cur.getLong(cur.getColumnIndexOrThrow("date")) on Cursor.
这是收到短信的时间(以毫秒为单位)。现在获取以毫秒为单位的当前时间。
long now = System.currentTimeMillis();//get Current Time
现在计算 M=分钟差:
long minutes=(now - sms_time)/(1000*60);
来源: