0
我正在使用Android SMS應用程序。它的一部分必須獲取收件箱數據(地址,日期,正文)和填充列表視圖。這是通過下面的代碼罰款:Android SMS日期函數調用
public void btnInboxOnClick {
// 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 cr = getContentResolver();
// Fetch Inbox SMS Message from Built-in Content Provider
Cursor c = cr.query(inboxURI, reqCols, null, null, null);
// Attached Cursor with adapter and display in listview
adapter = new SimpleCursorAdapter(this, R.layout.row, c,
new String[] { "body", "address", "date" }, new int[] {
R.id.lblMsg, R.id.lblNumber, R.id.lblDate });
lvMsg.setAdapter(adapter);
我想插入函數調用來顯示的,而不是從數據庫中獲取毫秒數有意義的時間串。我的功能代碼:
public static String millisToDate(String TimeMillis) {
String finalDate;
long tm = Long.parseLong(TimeMillis);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(tm);
Date date = calendar.getTime();
SimpleDateFormat outputFormat = new SimpleDateFormat("MMM-dd-yyyy HH:mm");
finalDate = outputFormat.format(date);
return finalDate;
}
任何嘗試調用函數編譯,但應用程序崩潰。我應該如何連接功能?