Android Question Module Receiver

Cleidson

Member
Hello everybody,
Once again I come to ask for your help from the forum. Next: I have a project to develop in which one of the requirements is to be able to register information in a remote database, according to the user's programming. However, this information must be registered with the application closed, without it being in the foreground or background. My tests showed that if they are in the foreground and background it works according to programming, but if the application is not “active” it does not work. It simply doesn't send the information as it should.
I spent some time reading about Module Receiver, which should be the standard for what I intend to program, but when it is activated it does not perform any action for which it was programmed. As it has already been said that Module Receiver does not start a service, due to Google restrictions, I tried it with a code module. Did not work.
Therefore, my question: Is it not possible to perform any action with the application closed?
If not, could anyone give me an idea on how to program this requirement so that it can be executed?
Thank you in advance for everyone's attention.
 

Cleidson

Member
Hi Erel,
Thank you for your attention. I used a Receiver Module plus StartServiceAtExact. In this case I need the application to make a selection and/or insertion into a remote database. It turns out that the scheduling schedule works well, but it does not perform selection or insertion if the application is not in the foreground or background. If it is in the foreground or in the background, it works, depending on the programming. I will test with StartReceiverAt.
 
Upvote 0

Cleidson

Member
Erel,
That's what I understood using the receiver. But the strange thing is that it starts at the scheduled time (I put some logs to indicate the code flow) and there is no insertion or selection execution in the remote database. If the application is closed, these commands are ignored. It only works if the application is active or paused.
I thought about using the code below to open the application. I did some tests and it works the way I need it to.

B4X:
Try
    Dim pm As PackageManager
    Dim i As Intent
    i = pm.GetApplicationIntent ("b4a.name")
    StartActivity (i)
Catch
    ToastMessageShow ("Failed to launch app!  Is it installed?", True)
End Try

But I had some questions:
1) Would I be breaking any Google rules, which could, in the future, have the application suspended from Google Play?
2) If not. Would there be a way to open and put the application in pause mode? The code above opens the application and keeps it active on the screen. I believe that it would not be pleasant for the user to suddenly see the application opening, without their action, even if this is described as happening in the application's terms of use.
 
Upvote 0

Cleidson

Member
Well, after spending some time researching a solution to the problem presented in the topics above, the solution below, at least in emulators, worked.

B4X:
Try

    If IsPaused(Main)  Then

        Dim pm As PackageManager
        Dim i As Intent                                  
        i = pm.GetApplicationIntent ("b4a.name")
        StartActivity (i)

        i.Initialize(i.ACTION_MAIN, "")
        i.AddCategory("android.intent.category.HOME")
        i.Flags = 0x10000000
        StartActivity(i)
       
    End If
Catch
    ToastMessageShow ("Failed to launch app! Is it installed?", True)
End Try


Even so, could anyone tell me if there would be any restrictions on Google's part in using this resource?
I thank you for your attention.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Well, after spending some time researching a solution to the problem presented in the topics above, the solution below, at least in emulators, worked.
This will not work in recent versions of Android. You cannot start an activity while the app is in the background unless you request the special "draw over apps" permission.
 
Upvote 0

Cleidson

Member
Erel,
According to your comments, I tested it on Android 13 with the appropriate requests to overlay the app and it worked. Well, now it's time to communicate to the user that if he wants the actions to be executed he can authorize the override, otherwise he can execute the actions manually.
Thank you in advance, again, for your attention.
 
Upvote 0
Top