Hi there!
I've finally got it!
The main problem was that from Android 10 (API level 29), there is a restriction for starting activities from the background (
https://developer.android.com/guide/components/activities/background-starts). In that link you can read that, to overcome that restriction, your application has to obtain the permission SYSTEM_ALERT_WINDOW (@jmpessoa , Could it be possible to add that permission to the list on Proyect -> Proyect properties -> [LAMW] Android Project Properties, so we don't have to insert it manually in AndroidManifest.xml?)
So, let's add it to AndroidManifest.xml:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
After that, we add our Manifest-declared receivers to the AndroidManifest.xml file like, for instance, this one to be notified when a SMS is received:
<receiver
android:name=".jBroadcastReceiver"
android:label="@string/app_name">
<intent-filter android:priority="1000">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
Then, we change the code of ../android_wizard/smartdesigner/java/jBroadcastReciever.java:
The line
controls.pOnBroadcastReceiver(pascalObj, intent);
turns into:
if (controls != null) {
controls.pOnBroadcastReceiver(pascalObj, intent); //normal behaviour
} else {
Context appContext = ctx.getApplicationContext();
String packageName = appContext.getPackageName();
Intent appIntent = new Intent();
appIntent.setClassName(packageName,packageName+".App");
appIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
appIntent.putExtras(intent);
appContext.startActivity(appIntent);
}
In essence, the new code does the same thing if the app which owns the jBroadcastReceiver is up and running but, if it isn't, the main activity of that App is started, and the bundle of the broadcast intent is copied to the new intent in charge of starting the activity.
The App is started and the OnActivityCreate method of the main activity is called, giving it the new intent. As that intent IS NOT a broadcast one, we shouldn't called with it directly the jBroadcastReceiver OnReceiver method. Instead, inside OnActivityCreate we should do something like this:
procedure TMainModule.OnActivityCreate(Sender: TObject; intentData: jObject);
var
bundle : jObject;
newIntent : jObject; //new SMS_RECEIVED [or any other broadcast event you want to handle] intent
begin
bundle := IntentManager.GetExtraBundle(intentData);
IntentManager.NewIntent();
IntentManager.SetAction('android.provider.Telephony.SMS_RECEIVED');
IntentManager.PutExtraBundle(bundle); //put the intentData extras bundle inside the newIntent
newIntent := IntentManager.GetIntent();
OnReceiver(self, newIntent); //now we can call the jBroadcastReceiver OnReceiver method
end;
I hope it can be helpful to someone.
@jmpessoa: It would be great if you consider to change the jBroadcastReceiver.java in Github, as it doesn't change the normal behaviour of the component and gives it more functionality (and, of course, that way it wouldn't erase my modifications in the next LAMW update
). Thanks in advance.