Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Run an apps from a service.


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 12 - Last Post: Dec 26, 2017 2:49 AM Last Post By: Dave Nottage
Berty Cortes Tr...

Posts: 11
Registered: 7/13/16
Run an apps from a service.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 19, 2017 7:28 PM
Hello everyone, because Android kills apps in the background, I need to run the apps from a service.
For windows I use:
WinExe (PChar ('Apps.exe' , SW_SHOWNORMAL);

What instruction is equivalent in Android?

Thanks....
Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: Run an apps from a service.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 19, 2017 7:47 PM   in response to: Berty Cortes Tr... in response to: Berty Cortes Tr...
Hello everyone, because Android kills apps in the background, I need to run the apps from a service.
For windows I use:
WinExe (PChar ('Apps.exe' , SW_SHOWNORMAL);

What instruction is equivalent in Android?

Given the package name:

uses 
  Androidapi.Helpers, Androidapi.JNI.GraphicsContentViewText;
 
procedure RunApp(const APackageName: string);
var
  LIntent: JIntent;
begin
  LIntent := TAndroidHelper.Context.getPackageManager.getLaunchIntentForPackage(StringToJString(APackageName));
  if LIntent <> nil then
    TAndroidHelper.Context.startActivity(LIntent);
end;


--
Dave Nottage [TeamB]
Find hints tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
Berty Cortes Tr...

Posts: 11
Registered: 7/13/16
Re: Run an apps from a service.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 19, 2017 9:27 PM   in response to: Dave Nottage in response to: Dave Nottage
Dave Nottage wrote:
Hello everyone, because Android kills apps in the background, I need to run the apps from a service.
For windows I use:
WinExe (PChar ('Apps.exe' , SW_SHOWNORMAL);

What instruction is equivalent in Android?

Given the package name:

uses 
  Androidapi.Helpers, Androidapi.JNI.GraphicsContentViewText;
 
procedure RunApp(const APackageName: string);
var
  LIntent: JIntent;
begin
  LIntent := TAndroidHelper.Context.getPackageManager.getLaunchIntentForPackage(StringToJString(APackageName));
  if LIntent <> nil then
    TAndroidHelper.Context.startActivity(LIntent);
end;


--
Dave Nottage [TeamB]
Find hints tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com

it is valid?
RunApp ('MonitorMoviles12.apk');

very grateful for your answer.

Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: Run an apps from a service.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 20, 2017 12:13 AM   in response to: Berty Cortes Tr... in response to: Berty Cortes Tr...
Berty Cortes Trujillo wrote:

it is valid?
RunApp ('MonitorMoviles12.apk');

very grateful for your answer.

No, you need to pass in the package name. If it was built with Delphi, and you have the project source, it'll be the
value for the package Key in the Version Info in the project options.

--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
Berty Cortes Tr...

Posts: 11
Registered: 7/13/16
Re: Run an apps from a service.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 20, 2017 9:10 AM   in response to: Dave Nottage in response to: Dave Nottage

No, you need to pass in the package name. If it was built with Delphi, and you have the project source, it'll be the
value for the package Key in the Version Info in the project options.

--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com

Very well, it is clear to me.
Dave how can I ask if the apps are running before RunApp ('myApp').

Thank you

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Run an apps from a service.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 20, 2017 9:23 AM   in response to: Berty Cortes Tr... in response to: Berty Cortes Tr...
Berty Cortes Trujillo wrote:

how can I ask if the apps are running before RunApp ('myApp').

Call Android's ActivityManager.getRunningAppProcesses() method and loop
through the returned list until you find the process you are interested
in:

https://developer.android.com/reference/android/app/ActivityManager.html#getRunningAppProcesses()

--
Remy Lebeau (TeamB)

Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: Run an apps from a service.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 26, 2017 2:49 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:


Sadly, that does not work for Android 5.1.1 and above. Google has since restricted the call to system applications.

--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Run an apps from a service.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 20, 2017 9:11 AM   in response to: Berty Cortes Tr... in response to: Berty Cortes Tr...
Berty Cortes Trujillo wrote:

For windows I use:

WinExe (PChar ('Apps.exe' , SW_SHOWNORMAL);

You shouldn't be using WinExec() at all, that has been deprecated since
Windows 95. Use CreateProcess() instead.

--
Remy Lebeau (TeamB)
Berty Cortes Tr...

Posts: 11
Registered: 7/13/16
Re: Run an apps from a service.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 20, 2017 9:30 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Berty Cortes Trujillo wrote:

For windows I use:

WinExe (PChar ('Apps.exe' , SW_SHOWNORMAL);

You shouldn't be using WinExec() at all, that has been deprecated since
Windows 95. Use CreateProcess() instead.

--
Remy Lebeau (TeamB)

This is already solved, I use a function RunApp ('MyApp').
My question is, before launching the app I need to know if it is already running.

Thank you Remy
Berty Cortes Tr...

Posts: 11
Registered: 7/13/16
Re: Run an apps from a service.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 20, 2017 10:16 AM   in response to: Berty Cortes Tr... in response to: Berty Cortes Tr...
Solved by
Dave Nottage
Berty Cortes Tr...

Posts: 11
Registered: 7/13/16
Re: Run an apps from a service.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 21, 2017 7:12 PM   in response to: Berty Cortes Tr... in response to: Berty Cortes Tr...
I discovered that the instruction:
LIntent:=TAndroidHelper.Context.getPackageManager.getLaunchIntentForPackage (StringToJString (APackageName));

It is always nil

For what reason?
Berty Cortes Tr...

Posts: 11
Registered: 7/13/16
Re: Run an apps from a service.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 21, 2017 9:26 PM   in response to: Berty Cortes Tr... in response to: Berty Cortes Tr...
Berty Cortes Trujillo wrote:
I discovered that the instruction:
LIntent:=TAndroidHelper.Context.getPackageManager.getLaunchIntentForPackage (StringToJString (APackageName));

It is always nil

For what reason?


the full name of the app must be indicated as a parameter.
RunApp ('com.embarcadero.myapp');

Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: Run an apps from a service.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 21, 2017 10:25 PM   in response to: Berty Cortes Tr... in response to: Berty Cortes Tr...
Berty Cortes Trujillo wrote:

the full name of the app must be indicated as a parameter.

As I mentioned in one of my replies, i.e. the value for "package" in the Version Info, in the project options. That
value is the full name of the app.

--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02