我正在尝试列出带有姓名和日期/时间的来电;
String[] _Projection = new String[]{CallLog.Calls.NUMBER,
CallLog.Calls.TYPE,
CallLog.Calls.CACHED_NAME,
CallLog.Calls.DATE};
String[] _ARGS = {String.valueOf(CallLog.Calls.INCOMING_TYPE)};
Cursor _cursor = managedQuery(CallLog.Calls.CONTENT_URI, _Projection, CallLog.Calls.TYPE + "=?", _ARGS, null);
int _num = _cursor.getColumnIndex(CallLog.Calls.NUMBER);
int _tip = _cursor.getColumnIndex(CallLog.Calls.TYPE);
int _name = _cursor.getColumnIndex(CallLog.Calls.CACHED_NAME);
int _date = _cursor.getColumnIndex(CallLog.Calls.DATE);
当我添加这两行时,应用程序停止;
String strDate = _cursor.getString(_date);
long lng = Long.parseLong(strDate);
或者用这一行;
long __lngDate = _cursor.getLong(_date);
如果没有这些行,应用程序无需日期/时间......我做错了什么?
注意:还有READ_CALL_LOG
的权限<uses-permission android:name="android.permission.READ_CALL_LOG"/>
谢谢和最诚挚的问候
答案 0 :(得分:0)
我自己找到了答案
public Loader<Cursor> onCreateLoader(int loaderID, Bundle args) {
Log.d("CallLogs", "onCreateLoader() >> loaderID : " + loaderID);
switch (loaderID) {
case URL_LOADER:
String mSelectionClause = android.provider.CallLog.Calls.DATE+ " >= ?";
String[]mSelectionArgs = {createDate()};
// Returns a new CursorLoader
return new CursorLoader(
mContext, // Parent activity context
CallLog.Calls.CONTENT_URI, // Table to query
null, // Projection to return
mSelectionClause, // No selection clause
mSelectionArgs, // No selection arguments
CallLog.Calls.DATE + " desc" // Default sort order
);
default:
return null;
}
}
public String createDate()
{
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, -1);
return String.valueOf(calendar.getTimeInMillis());
}