Lazarus

Programming => Operating Systems => Android => Topic started by: Mongkey on February 28, 2021, 04:15:04 am

Title: [LAMW] is it possible sending key to another android app
Post by: Mongkey on February 28, 2021, 04:15:04 am
Any idea?
Title: Re: [LAMW] is it possible sending key to another android app
Post by: ASBzone on February 28, 2021, 04:54:25 am
You may need to be a bit more verbose in what you are requesting, and what you are already experiencing when you try to accomplish it.
Title: Re: [LAMW] is it possible sending key to another android app
Post by: Mongkey on February 28, 2021, 01:31:58 pm
I just want to send / inject whatsapp activity with enter key, after opening whatsapp intent, so the message automatically sent without touching send button.
Title: Re: [LAMW] is it possible sending key to another android app
Post by: Mongkey on February 28, 2021, 01:36:37 pm
I want to integrate whatsapp, as appointment reminder by sending whatsapp message automatically without doing 1 by 1 . Thank you for your reply ABSzone.

This screenshots are what i did so far with awesome LAMW.
Title: Re: [LAMW] is it possible sending key to another android app
Post by: jmpessoa on February 28, 2021, 06:33:29 pm

Hi, Mongkey...

Look for some pure java/android example and you will learn what intent parameters you need....
Title: Re: [LAMW] is it possible sending key to another android app
Post by: Mongkey on March 01, 2021, 01:29:18 am
all i did just learning from LAMW samples, pure java just like an alien for me  %), opening WA intent -> put some text -> start intent -> pressing OK, i just need set auto pressing for OK/ENTER button, (hi hi hi, this just like what appium do)

Thanks for your reply JMPessoa,
 
I found many intent parameters here:
https://github.com/aosp-mirror/platform_frameworks_base/blob/master/core/res/AndroidManifest.xml#L2515

I think i need more coffee to accomplish this, for pull stuck type programmer like me, thank you.
Title: Re: [LAMW] is it possible sending key to another android app
Post by: Segator on March 01, 2021, 04:29:53 pm
Hi, Mongkey, i think that you need an special android 8.0> function that interact with touch screen, this require special permission and is not recomended for securoty reason, try to find the correct Intent params to do that like @jmpessoa say, this is an java example from https://stackoverflow.com/questions/19081654/send-text-to-specific-contact-programmatically-whatsapp (https://stackoverflow.com/questions/19081654/send-text-to-specific-contact-programmatically-whatsapp)

Code: Pascal  [Select][+][-]
  1. PackageManager packageManager = context.getPackageManager();
  2.     Intent i = new Intent(Intent.ACTION_VIEW);
  3.  
  4.     try {
  5.         String url = "https://api.whatsapp.com/send?phone="+ phone +"&text=" + URLEncoder.encode(message, "UTF-8");
  6.         i.setPackage("com.whatsapp");
  7.         i.setData(Uri.parse(url));
  8.         if (i.resolveActivity(packageManager) != null) {
  9.             context.startActivity(i);
  10.         }
  11.     } catch (Exception e){
  12.         e.printStackTrace();
  13.     }
  14.  

and you can adapt to the pascal lamw way like this (not tested):

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.jButton1Click(Sender: TObject);
  2. var
  3.   phone,message:string;
  4. begin
  5.   phone:='12345678';
  6.   message:='I am the body.';
  7.   jIntentManager1.SetAction(iaSENDTO);
  8.   jIntentManager1.SetDataUri(self.ParseUri('https://api.whatsapp.com/send?phone='+ phone +'&text=' + self.UriEncode(message)));
  9.   jIntentManager1.SetDataAndType(self.ParseUri('https://api.whatsapp.com/send?phone='+ phone +'&text=' + self.UriEncode(message)),'text/plain');
  10.   jIntentManager1.SetPackage('com.whatsapp');
  11.   jIntentManager1.StartActivity()
  12. end;
  13.  
Title: Re: [LAMW] is it possible sending key to another android app
Post by: Mongkey on March 02, 2021, 01:18:38 am
thanks, segator,

IaSENDTO not working on my android 10 handset, only IaVIEW does the job, am i missing something?

IaSEND working code:
Code: Pascal  [Select][+][-]
  1. var
  2.   phone,message:string;
  3. begin
  4.   phone:='62123456';
  5.   message:='I am the body.';
  6.   if jIntentManager1.IsPackageInstalled('com.whatsapp') then
  7.   begin
  8.       jIntentManager1.SetPackage('com.whatsapp');
  9.       jIntentManager1.SetAction(IaSEND);
  10.       jIntentManager1.SetMimeType('text/plain');
  11.       jIntentManager1.SetFlag(ifActivityNewTask);
  12.       jIntentManager1.PutExtraText(message);
  13.       //jIntentManager1.SetDataUri(self.ParseUri('https://api.whatsapp.com/send?phone='+ phone +'&text=' + self.UriEncode(message)));
  14.       //jIntentManager1.PutExtraString('Jid', phone +'@s.whatsapp.net');
  15.  
  16.       jIntentManager1.StartActivity()
  17.   end
  18.  
TinyPortal © 2005-2018