Вопрос

I have a problem with Jstring down Delphi-XE5 for Android app. Actually i'm trying to access the android calendar using the following sentences:

  projection: array[1..4] of string=('_id','account_name','calendar_display_name','owner_account');

  Uri      :=TJnet_Uri.JavaClass.parse(StringToJString('content://com.android.calendar/events'));
  managedCursor := SharedActivity.getContentResolver.query(Uri, projection, nil, nil, nil);

And the problem is that the last query must received projection as Jstring.

I have been trying as well :

projection: array[1..4] of JString=  (StringToJString('_id'),StringToJString('account_name'),StringToJString('calendar_display_name'),StringToJString('owner_account'));

But it return me the following error:

[DCC Error] Unit5.pas(46): E2250 There is no overloaded version of 'query' that can be called with these arguments

Any Ideas?

Это было полезно?

Решение

The projection parameter of the query function must be a TJavaObjectArray<JString> like is shown in the signature of the query method of the JContentResolver class.

  function query(uri: Jnet_Uri; projection: TJavaObjectArray<JString>; selection: JString; selectionArgs: TJavaObjectArray<JString>; sortOrder: JString): JCursor; cdecl; overload;
  function query(uri: Jnet_Uri; projection: TJavaObjectArray<JString>; selection: JString; selectionArgs: TJavaObjectArray<JString>; sortOrder: JString; cancellationSignal: JCancellationSignal): JCursor; cdecl; overload;

So you can pass this parameter on this way

  projection : TJavaObjectArray<JString>;
begin
  projection := TJavaObjectArray<JString>.Create(4);
  projection.Items[0] := StringToJString('_id');
  projection.Items[1] := StringToJString('account_name');
  projection.Items[2] := StringToJString('calendar_display_name');
  projection.Items[3] := StringToJString('owner_account');

  Uri      :=TJnet_Uri.JavaClass.parse(StringToJString('content://com.android.calendar/events'));
  SharedActivity.getContentResolver.query(Uri, projection, nil, nil, nil);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top