Android Question Receive intents with Android 10

Creideiki

Active Member
Licensed User
Longtime User
Hi,

I wrote an app that receives intents which are sent by Tasker. The app worked till I got a new phone with Android 10.

A little test app sends an intent and receives it itself. It was originally written with targetSdkVersion set to 14. In this version it worked (even with the Android 10 phone).
Now I updated to targetSdkVersion 26 and it doesn't work any more.
Code: Copy
AddReceiverText(TargetService, <intent-filter>
    <action android:name="de.helmutbender.setstatus.NEW_STATUS" />
    <data android:scheme="helmut" />
</intent-filter>)
SetReceiverAttribute(TargetService, android:exported, true)
Code: Copy
Sub btISend_Click
    Dim myIntent As Intent
    myIntent.Initialize("de.helmutbender.setstatus.NEW_STATUS", "helmut://6")
    Dim p As Phone
    p.SendBroadcastIntent(myIntent)
    Log("IntentTester: Intent sent.")
End Sub
Code: Copy
Sub Service_Start (StartingIntent As Intent)
    Log("IntentTest starting with " & StartingIntent.Action & " : " & StartingIntent.GetData)
    Service.StopAutomaticForeground 'Call this when the background task completes (if there is one)
End Sub

I read through the forum the last hours... I don't find what's wrong.
What have I to do to make it work with Android 10?
 
Upvote 0
Does it make sense to send a broadcast intent just to receive it by the same app? Wouldn´t it be easier just to call a sub in the app instead of sending a broadcastintent?
Have you tried to send the intent from another app?
No, certainly not. It's only a test app. The "original" app tries to recieve intents from Tasker.

check the unfiltered log also
Hm... that's very much logging... but I found something:
Code: Copy
Background execution not allowed: receiving Intent { act=de.helmutbender.setstatus.NEW_STATUS dat=helmut://6 flg=0x10 } to de.helmutbender.intenttest/.targetservice$targetservice_BR

Well, searching for "background execution" and then "foreground service" gives me many hits... so I will look into this.
Thanks so far :)
 
Upvote 0
When I read this, it seems, that B4A should handle that itself. And it doesn't work when the app is in forground either.
So what am I doing wrong?
 
Upvote 0
I found this and adapted it as follows:
B4X: Copy
myIntent.SetComponent("de.helmutbender.intenttest/.targetservice$targetservice_BR")
Now it works.

But WHY?

What does SetComponent do and why is it necessary?
...and how can I tell Tasker to set the component?
 
Upvote 0
ok... there are only a view exceptions where broadcasts can be recieved by normal, in the manifest declared static implicit intents.

So what can I do to get messages from other apps (Tasker, in my case)?
1) send the intent to a specific component (see above).
Problem: I don't know how I can tell Tasker to do this...
2) Declare the broadcast receiver dynamically.
Problem: this receiver could get killed in background. I can't be shure it runs.
3) I don't need a "broadcast" in this sense. I have one transmitter and one receiver. Tasker has a setting to create an intent that starts a service instead broadcasting.
Problem: Neither I know how to setup Tasker correctly nor do I know how to setup the B4A app correctly... and I don't know what to search...
 
Upvote 0
So the answer of my question is: Receiving Broadcast Intents is much more difficult with new Android versions as before. The reason is linked by Erel above.
It is possible, but the sender should set the component explicitly.
 
Upvote 0

Similar Threads

  • Article Article
Android Code Snippet Start receiver at exact time
Replies
2
Views
8K
Replies
48
Views
53K
Replies
8
Views
17K
  • Locked
  • Article Article
Android Tutorial Intent Based Camera
Replies
48
Views
50K
Back
Top