Starting the push service sample from another B4A app

bluedude

Well-Known Member
Licensed User
Longtime User
Hi,

I'm using the push sample service and I want to be able to start/stop this service from another app.

It seems there are some permission issues to do that because I get:

Not allowed to start service intent without permission not exported from uid 10100. I signed both packages with the same sign key.

I DON'T want to register/unregister from the calling app., just start and stop the service.

Any suggestions how to cope with the permissions? Probably something in the Android manifest of the service.

Cheers,
 

bluedude

Well-Known Member
Licensed User
Longtime User
I have added this to the manifest of the service app.

SetReceiverAttribute(svcPush, android:permission, "$PACKAGE$.permission.svcpush")
SetReceiverAttribute(svcPush, android:protectionLevel, "signature")
SetReceiverAttribute(svcPush, android:exported, "true")

No luck.
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Stop service

Hmm, that is a good point.

That brings up another question. Can I register/unregister by calling it from another B4A app then? Or would that raise the same permission problems?

In a normal situation I can probably call Stop/Start a service from another app., haven't tried that with a normal service.

Cheers,
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Intent filters

I'm actually not talking about intent filters at all. I just one to start a service in another app. from a new app.

Like StartService and StopService that you normal use in the same package inside an activity.

I tried that but gave me the permission error.

Cheers,
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
So I use this or something similar to start the service in another app. (my own) but always get permission errors, even with normal services.

Dim i As Intent
i.Initialize("", "")
i.SetComponent("nl.openhanced.apps.template/.svcgps")
StartService(i)
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Not working

Hi Erel,

Unfortunately this does not seem to work. Do I need to change anything in the manifest of the service itself?

I think I have to delete this functionality from the requirements list because it does not seem to work.

Should it work or is it impossible to start services from other apps.?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It works.

You should add the following manifest code to the target application:
B4X:
SetReceiverAttribute(HttpUtilsService, android:exported, "true")

And then create an intent similar to:
B4X:
Dim p As Phone
Dim i As Intent
i.Initialize("", "")
i.SetComponent("anywheresoftware.b4a.samples.flickr/.httputilsservice$httputilsservice_BR")
p.SendBroadcastIntent(i)

You should of course change the package name and service module name.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It works.

You should add the following manifest code to the target application:
B4X:
SetReceiverAttribute(HttpUtilsService, android:exported, "true")

And then create an intent similar to:
B4X:
Dim p As Phone
Dim i As Intent
i.Initialize("", "")
i.SetComponent("anywheresoftware.b4a.samples.flickr/.httputilsservice$httputilsservice_BR")
p.SendBroadcastIntent(i)

You should of course change the package name and service module name.
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
I'm trying to do this in my app as well. I am trying to start a certain activity in another app I made. I think I mostly have it done, but when trying to compile my app I get the following error:

Compiling code. Error
Module: favsguide_br not found.

I added the following to the manifest editor for the receiving app:

B4X:
SetReceiverAttribute(FavsGuide, android:exported, "true")

I'm not sure what I'm doing wrong, or if the code snippets in this thread are specifically for services.

Ideally I would like to be able to start that specific activity in my app, but only from my other app (if possible).
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
Nevermind. I got it straightened out. I was close, but since it wasn't a service but rather an activity, I just needed to put the following in the target app's manifest:

B4X:
SetActivityAttribute(FavsGuide, android:exported, "true")
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
It works.

You should add the following manifest code to the target application:
B4X:
SetReceiverAttribute(HttpUtilsService, android:exported, "true")

And then create an intent similar to:
B4X:
Dim p As Phone
Dim i As Intent
i.Initialize("", "")
i.SetComponent("anywheresoftware.b4a.samples.flickr/.httputilsservice$httputilsservice_BR")
p.SendBroadcastIntent(i)

You should of course change the package name and service module name.


I would like to start a service in one of my apps from another one of my apps. Is this how I should do it? I don't necessarily want to send it data or communicate with it. I only want to get it started.

Also important to what I am trying to do: Can I detect if that service is running from my other app?

Essentially what I am doing is this: I want to see if a service is running in another app of mine. If it is, I want to stop it. Then later on (about 20 seconds later) I want to start it again only if it was already started or running. Is this possible? My issue is that the service that may be running in my other app could possibly cause problems with a function of my second app so I want to suspend then resume it if possible.
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
So to make sure I understand this correctly:

App A = my second add-on app
App B = my other app that contains the service in question

If the service is not running and I start it from App A, the service will run in its own process regardless of whether or not App B is running

If the service is running (in memory) and App B is running (in memory), I can stop the service then restart the service and it will still be part of App B's process

Is this right?

If so, I assume I can start it with (just using sample code from this thread):

B4X:
Dim p As Phone
Dim i As Intent
i.Initialize("", "")
i.SetComponent("anywheresoftware.b4a.samples.flickr/.httputilsservice$httputilsservice_BR")
p.SendBroadcastIntent(i)

So what code would I use to stop it?

What code can I use to see if it is running?

The service starts every 10 seconds. It may not be actively doing something, but I want to be able to tell if it is doing something or scheduled to do something (i.e. it could start up again while App A is trying to do its thing).

I may even be over-thinking this. The service in question is not set to "run in the foreground". So is it possible that while my add-on app (App A) is doing its thing for a few seconds and then closing that this alone would temporarily suspend the service in App B and keep the two from interfering with each other?

What the service does is pulls some data from a satellite receiver every 10 seconds then refreshes a notification. The add-on app can send macros (several remote commands) one after another. But if they get interrupted it can cause the macros to fail. So I don't want my other service requesting data from that same satellite receiver while the macro is executing.

Another thought:
Another option would be that my service in App B checks to see if App A is actively running (or a service in App A is running) and if so, reschedule itself for 20 seconds later. But if I did this, I would need to know if the app is in the foreground or if it is suspended. App A either sends the commands from the activity or starts its own service to send the commands, but once done, Activity.Finish is called. App A (or its service) is only doing something for 1 second to maybe 10 seconds.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
App A = my second add-on app
App B = my other app that contains the service in question

If the service is not running and I start it from App A, the service will run in its own process regardless of whether or not App B is running

If the service is running (in memory) and App B is running (in memory), I can stop the service then restart the service and it will still be part of App B's process

Is this right?
No. Service B will always run inside the process of App B. If the App B is not running then it will start running when Service B is started. It doesn't mean that any activity will appear. It just means that the service B is tied to the process of app B. If later the user starts any activity of app B then it will also run under process B.
 
Upvote 0

cncncn

Member
Licensed User
Longtime User
B4X:
Version=2.71
IconFile=
NumberOfModules=4
Module1=smbService
ModuleVisible1=1
Module2=bibli
ModuleVisible2=1
Module3=deuxieme
ModuleVisible3=0
Module4=deux
ModuleVisible4=1
Package=b4a.example
DoNotOverwriteManifest=False
ManifestCode='This code will be applied to the manifest file during compilation.~\n~'You do not need to modify it in most cases.~\n~'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136~\n~AddManifestText(~\n~<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14"/>~\n~<supports-screens android:largeScreens="true" ~\n~    android:normalScreens="true" ~\n~    android:smallScreens="true" ~\n~    android:anyDensity="true"/>)~\n~SetApplicationAttribute(android:icon, "@drawable/icon")~\n~SetApplicationAttribute(android:label, "$LABEL$")~\n~'End of default text.~\n~
UserTypesHint=
NumberOfFiles=0
NumberOfLibraries=5
Library1=core
Library2=customprogressdialog
Library3=mlfiles
Library4=phone
Library5=smb
@EndOfDesignText@
#Region  Project Attributes
    #ApplicationLabel: Modification
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
  

End Sub

Sub Activity_Resume
  
    Dim p As Phone
    Dim i As Intent
    i.Initialize("","")
    i.SetComponent("anywheresoftware.b4a.NGV_app/.jeton$jeton_BR")
    p.SendBroadcastIntent(i)
  
  
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
B4X:
Type=Service
Version=2.71
@EndOfDesignText@
#Region  Service Attributes
    #StartAtBoot: False
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub
Sub Service_Create
    Log("service jeton")
End Sub

Sub Service_Start (StartingIntent As Intent)
    Log("service jeton")
End Sub

Sub Service_Destroy

End Sub
Hi,

Not working

my application "jeton" to open token service my main application "NGVApp_Test"
I do not understand why its not working
 
Last edited:
Upvote 0
Top