Recent

Author Topic: [LAMW] How to prompt contact picker directly? [SOLVED]  (Read 257 times)

Segator

  • Full Member
  • ***
  • Posts: 159
    • https://github.com/Nenirey
[LAMW] How to prompt contact picker directly? [SOLVED]
« on: December 22, 2020, 10:33:17 pm »
i am trying to make an intent to open the contact manager directly but in the demos just Open a Dialog Recently with some items including the contacts item and the user must select it firt and them the contact this is some difficult and confusing for some users, this is the demo code:
Code: Pascal  [Select][+][-]
  1. jIntentManager1.SetAction(jIntentManager1.GetActionGetContentUri());
  2. jIntentManager1.SetMimeType('vnd.android.cursor.item/phone_v2');
  3. if jIntentManager1.ResolveActivity() then
  4. begin
  5.   jIntentManager1.StartActivityForResult(1003, 'Dial ...');
  6. end
  7. else
  8.   ShowMessage('no contact manager found');
  9.  
  10.  
but this is no an intent directly to the contact manager, i test some example from internet but it fail to ResolveActivity, how i can do?
« Last Edit: January 23, 2021, 11:27:52 pm by Segator »
i am Reinier, Nenirey and Segator :) https://github.com/Nenirey

Segator

  • Full Member
  • ***
  • Posts: 159
    • https://github.com/Nenirey
Re: [LAMW] How to prompt contact picker directly? [SOLVED]
« Reply #1 on: January 23, 2021, 11:26:33 pm »
Finally i resolve how make the intent action, thanks to @jmpessoa and take a look to the jIntentManager.java code, here is the way:
Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.jButton1Click(Sender: TObject);
  2. begin
  3.     if isRunTimePermissionGranted('android.permission.READ_CONTACTS') then
  4.   begin
  5.     jIntentManager1.SetAction(iaPick);
  6.     jIntentManager1.SetDataUri(jIntentManager1.GetContactsPhoneUri());
  7.      if jIntentManager1.ResolveActivity() then
  8.      begin
  9.        jIntentManager1.StartActivityForResult(2003, 'Dial ...');
  10.      end
  11.      else
  12.        ShowMessage('Debe instalar una app de contactos');
  13.   end
  14.   else
  15.   begin
  16.     Self.RequestRuntimePermission('android.permission.READ_CONTACTS', 2001);
  17.   end;
  18. end;
  19.  
  20. procedure TAndroidModule1.AndroidModule1ActivityResult(Sender: TObject;
  21.   requestCode: integer; resultCode: TAndroidResult; intentData: jObject);
  22. var
  23.    jContactUri: jObject;
  24.    strContactNumber: string;
  25. begin
  26.     if (requestCode = 2003) and (resultcode=RESULT_OK) then
  27.     begin
  28.       strContactNumber:= '';
  29.       jContactUri:=jIntentManager1.GetDataUri(intentData);
  30.       strContactNumber:= jIntentManager1.GetContactNumber(jContactUri);
  31.       ShowMessage(strContactNumber);
  32.     end;
  33. end;
  34.  
i am Reinier, Nenirey and Segator :) https://github.com/Nenirey

 

TinyPortal © 2005-2018