Recent

Author Topic: [LAMW] is it possible sending key to another android app  (Read 640 times)

Mongkey

  • New Member
  • *
  • Posts: 18
[LAMW] is it possible sending key to another android app
« on: February 28, 2021, 04:15:04 am »
Any idea?
« Last Edit: February 28, 2021, 04:23:04 am by Mongkey »

ASBzone

  • Hero Member
  • *****
  • Posts: 595
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: [LAMW] is it possible sending key to another android app
« Reply #1 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.
-ASB: https://www.BrainWaveCC.com/

Lazarus v2.0.13 r64843 / FPC v3.2.1-r49055 (via FpcUpDeluxe) -- Windows 64-bit install w/Win32 and Linux/Arm cross-compiles
Primary System: Windows 10 Pro x64, Version 2009 (Build 19042)
Other Systems: Windows 10 Pro x64, Version 2009 (Build 19042) or greater

Mongkey

  • New Member
  • *
  • Posts: 18
Re: [LAMW] is it possible sending key to another android app
« Reply #2 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.

Mongkey

  • New Member
  • *
  • Posts: 18
Re: [LAMW] is it possible sending key to another android app
« Reply #3 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.
« Last Edit: March 01, 2021, 01:52:40 am by Mongkey »

jmpessoa

  • Hero Member
  • *****
  • Posts: 1791
Re: [LAMW] is it possible sending key to another android app
« Reply #4 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....
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Mongkey

  • New Member
  • *
  • Posts: 18
Re: [LAMW] is it possible sending key to another android app
« Reply #5 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.
« Last Edit: March 01, 2021, 01:43:21 am by Mongkey »

Segator

  • Full Member
  • ***
  • Posts: 164
    • https://github.com/Nenirey
Re: [LAMW] is it possible sending key to another android app
« Reply #6 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

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.  
i am Reinier, Nenirey and Segator :) https://github.com/Nenirey

Mongkey

  • New Member
  • *
  • Posts: 18
Re: [LAMW] is it possible sending key to another android app
« Reply #7 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.  
« Last Edit: March 02, 2021, 02:44:53 am by Mongkey »

 

TinyPortal © 2005-2018