您好,这是我的代码:
function FetchCalls:string;
var
cursor: JCursor;
uri: Jnet_Uri;
CACHED_FORMATTED_NUMBER, CACHED_LOOKUP_URI, CACHED_MATCHED_NUMBER, CACHED_NAME,
CACHED_NORMALIZED_NUMBER, CACHED_NUMBER_LABEL, CACHED_NUMBER_TYPE, CACHED_PHOTO_ID,
CONTENT_ITEM_TYPE, CONTENT_TYPE, COUNTRY_ISO, DATA_USAGE, DATE, DEFAULT_SORT_ORDER, DURATION,
EXTRA_CALL_TYPE_FILTER, FEATURES, IS_READ, LIMIT_PARAM_KEY, NEW, NUMBER, NUMBER_PRESENTATION,
OFFSET_PARAM_KEY, PHONE_ACCOUNT_COMPONENT_NAME, PHONE_ACCOUNT_ID, TRANSCRIPTION, TYPEX, VOICEMAIL_URI : integer;
msgunixtimestampms:int64;
CACHED_FORMATTED_NUMBERx, CACHED_LOOKUP_URIx, CACHED_MATCHED_NUMBERx, CACHED_NAMEx,
CACHED_NORMALIZED_NUMBERx, CACHED_NUMBER_LABELx, CACHED_NUMBER_TYPEx, CACHED_PHOTO_IDx,
CONTENT_ITEM_TYPEx, CONTENT_TYPEx, COUNTRY_ISOx, DATA_USAGEx, DATEx, DEFAULT_SORT_ORDERx, DURATIONx,
EXTRA_CALL_TYPE_FILTERx, FEATURESx, IS_READx, LIMIT_PARAM_KEYx, NEWx, NUMBERx, NUMBER_PRESENTATIONx,
OFFSET_PARAM_KEYx, PHONE_ACCOUNT_COMPONENT_NAMEx, PHONE_ACCOUNT_IDx, TRANSCRIPTIONx, TYPEXx, VOICEMAIL_URIx : string;
begin
uri:=StrToJURI('content://call_log/calls');
cursor := SharedActivity.getContentResolver.query(uri, nil, nil,nil,nil);
CACHED_FORMATTED_NUMBER:=cursor.getColumnIndex(StringToJstring('CACHED_FORMATTED_NUMBER'));
CACHED_LOOKUP_URI:=cursor.getColumnIndex(StringToJstring('CACHED_LOOKUP_URI'));
CACHED_MATCHED_NUMBER:=cursor.getColumnIndex(StringToJstring('CACHED_MATCHED_NUMBER'));
CACHED_NAME:=cursor.getColumnIndex(StringToJstring('CACHED_NAME'));
CACHED_NORMALIZED_NUMBER:=cursor.getColumnIndex(StringToJstring('CACHED_NORMALIZED_NUMBER'));
CACHED_NUMBER_LABEL:=cursor.getColumnIndex(StringToJstring('CACHED_NUMBER_LABEL'));
CACHED_NUMBER_TYPE:=cursor.getColumnIndex(StringToJstring('CACHED_NUMBER_TYPE'));
CACHED_PHOTO_ID:=cursor.getColumnIndex(StringToJstring('CACHED_PHOTO_ID'));
CONTENT_ITEM_TYPE:=cursor.getColumnIndex(StringToJstring('CONTENT_ITEM_TYPE'));
CONTENT_TYPE:=cursor.getColumnIndex(StringToJstring('CONTENT_TYPE'));
COUNTRY_ISO:=cursor.getColumnIndex(StringToJstring('COUNTRY_ISO'));
DATA_USAGE:=cursor.getColumnIndex(StringToJstring('DATA_USAGE'));
DATE:=cursor.getColumnIndex(StringToJstring('DATE'));
DEFAULT_SORT_ORDER:=cursor.getColumnIndex(StringToJstring('DEFAULT_SORT_ORDER'));
DURATION:=cursor.getColumnIndex(StringToJstring('DURATION'));
EXTRA_CALL_TYPE_FILTER:=cursor.getColumnIndex(StringToJstring('EXTRA_CALL_TYPE_FILTER'));
FEATURES:=cursor.getColumnIndex(StringToJstring('FEATURES'));
IS_READ:=cursor.getColumnIndex(StringToJstring('IS_READ'));
LIMIT_PARAM_KEY:=cursor.getColumnIndex(StringToJstring('LIMIT_PARAM_KEY'));
NEW:=cursor.getColumnIndex(StringToJstring('NEW'));
NUMBER:=cursor.getColumnIndex(StringToJstring('NUMBER'));
NUMBER_PRESENTATION:=cursor.getColumnIndex(StringToJstring('NUMBER_PRESENTATION'));
OFFSET_PARAM_KEY:=cursor.getColumnIndex(StringToJstring('OFFSET_PARAM_KEY'));
PHONE_ACCOUNT_COMPONENT_NAME:=cursor.getColumnIndex(StringToJstring('PHONE_ACCOUNT_COMPONENT_NAME'));
PHONE_ACCOUNT_ID:=cursor.getColumnIndex(StringToJstring('PHONE_ACCOUNT_ID'));
NUMBER_PRESENTATION:=cursor.getColumnIndex(StringToJstring('NUMBER_PRESENTATION'));
TRANSCRIPTION:=cursor.getColumnIndex(StringToJstring('TRANSCRIPTION'));
TYPEX:=cursor.getColumnIndex(StringToJstring('TYPE'));
while (cursor.moveToNext) do begin
CACHED_FORMATTED_NUMBERx:=JStringToString(cursor.getString(CACHED_FORMATTED_NUMBER));
CACHED_LOOKUP_URIx:=JStringToString(cursor.getString(CACHED_LOOKUP_URI));
CACHED_MATCHED_NUMBERx:=JStringToString(cursor.getString(CACHED_MATCHED_NUMBER));
CACHED_NAMEx:=JStringToString(cursor.getString(CACHED_NAME));
CACHED_NORMALIZED_NUMBERx:=JStringToString(cursor.getString(CACHED_NORMALIZED_NUMBER));
CACHED_NUMBER_LABELx:=JStringToString(cursor.getString(CACHED_NUMBER_LABEL));
CACHED_NUMBER_TYPEx:=JStringToString(cursor.getString(CACHED_NUMBER_TYPE));
CACHED_PHOTO_IDx:=JStringToString(cursor.getString(CACHED_PHOTO_ID));
CONTENT_ITEM_TYPEx:=JStringToString(cursor.getString(CONTENT_ITEM_TYPE));
CONTENT_TYPEx:=JStringToString(cursor.getString(CONTENT_TYPE));
COUNTRY_ISOx:=JStringToString(cursor.getString(COUNTRY_ISO));
DATA_USAGEx:=JStringToString(cursor.getString(DATA_USAGE));
DATEx:=JStringToString(cursor.getString(DATE));
DEFAULT_SORT_ORDERx:=JStringToString(cursor.getString(DEFAULT_SORT_ORDER));
DURATIONx:=JStringToString(cursor.getString(DURATION));
EXTRA_CALL_TYPE_FILTERx:=JStringToString(cursor.getString(EXTRA_CALL_TYPE_FILTER));
FEATURESx:=JStringToString(cursor.getString(FEATURES));
IS_READx:=JStringToString(cursor.getString(IS_READ));
LIMIT_PARAM_KEYx:=JStringToString(cursor.getString(LIMIT_PARAM_KEY));
NEWx:=JStringToString(cursor.getString(NEW));
NUMBERx:=JStringToString(cursor.getString(NUMBER));
NUMBER_PRESENTATIONx:=JStringToString(cursor.getString(NUMBER_PRESENTATION));
OFFSET_PARAM_KEYx:=JStringToString(cursor.getString(OFFSET_PARAM_KEY));
PHONE_ACCOUNT_COMPONENT_NAMEx:=JStringToString(cursor.getString(PHONE_ACCOUNT_COMPONENT_NAME));
PHONE_ACCOUNT_IDx:=JStringToString(cursor.getString(PHONE_ACCOUNT_ID));
NUMBER_PRESENTATIONx:=JStringToString(cursor.getString(NUMBER_PRESENTATION));
TRANSCRIPTIONx:=JStringToString(cursor.getString(TRANSCRIPTION));
TYPEXx:=JStringToString(cursor.getString(TYPEX));
Result:=TYPEXx+CACHED_NAMEx+NUMBERx;
end;
end;
并使用...... 这是使用方法
Memo1.lines.add(FetchCalls);
但是当我尝试使用此功能时出现此错误:
" JAVA.LANG.LLLEGALSTATEEXCEPTION:COULDN'读取行0,COL-1来自CURSORWINDOW。确保游标在从其访问数据之前正确初始化。
任何想法如何解决这个问题?
非常感谢
答案 0 :(得分:1)
我解决了你的问题。这是非常好的代码我曾经复制和修复你有相同的错误。 首先包括
Androidapi.JNI.Provider, FMX.Helpers.Android
根据你的delphi版本。在我的案例中,我使用了Delphi 10.1 Berlin。
第二次全部替换
cursor.getColumnIndex(StringToJstring('XXXX'));
到
cursor.getColumnIndex( TJCallLog_Calls.JavaClass.XXXX );
作为CACHED_NAME的示例,它将是
CACHED_NAME:=cursor.getColumnIndex( TJCallLog_Calls.JavaClass.CACHED_NAME );
编译完一切后,它工作得很好。我将给你的另一个建议是评论或删除你提取的数据,但你不能使用。在代码的最后,您只返回TYPE,CACHED_NAME和NUMER。从其他字段获取数据的所有其他调用都是不必要的。