Android Tutorial Receivers and Services in 2023+

Status
Not open for further replies.

Star-Dust

Expert
Licensed User
Longtime User
A few use cases for receivers:
  • Handling push notifications
  • Scheduling receivers to run
  • Home screen widgets
  • Activity recognition
  • Run after boot
  • And more...
Thanks for the great work.
Is it possible to have a complete list of cases in which the intent can be used? Is there any Android documentation we can consult?

If I'm not mistaken you have updated some of your examples for the new version. Can you list which examples have been updated?
It may be useful to download the new versions to study them and better understand how to use this tool
 

ema01

Member
Licensed User
Longtime User
Hi, could receivers be used to launch the application if a bluetooth device is in range?
Because you basically can't (or don't want to have) a service running 24/7 looking for devices
 

Creideiki

Active Member
Licensed User
Longtime User
When do I need to switch from service to receiver?
* When I use 31 (or 32?) as targetSDK? (ok, that's quite obvious)
* When I run on a device with Android 12+ without changing my targetSDK?
* When I switch to B4A 12.2?

In other words: Is this only relevant when I use targetSDK >= 31 or in other cases, too?
 
1. Yes.
2. No.
3. No.

4. Google Play requires setting the targetSdkVersion to 31.
5. It is quite simple to switch to receivers and I suggest doing it anyway.
Hi Erel,
First of all, thanks for your work. I want to receive broadcast intents in my app. I've tested broadcastreceiver library, and worked fine in the demo example, but when I add to my app with api 33, it doesn't work.
So I'm testing with new module of receiver type, adding the manifest, but I don't get the receive envent.
What is the problem?

this is my manifest.xml:
B4X:
AddReceiverText(MyReceiver, <intent-filter>
    <action android:name="com.my.application.CUSTOM_INTENT"/>
</intent-filter>)

and this is myReceiver module:
B4X:
Sub Process_Globals
    
End Sub

'Called when an intent is received.
'Do not assume that anything else, including the starter service, has run before this method.
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)   
    Log(StartingIntent)
End Sub
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…