Android Question [solved] Problem receiving intent from tasker

Creideiki

Active Member
Licensed User
Longtime User
Hi,

I'm trying to control my B4A-App with tasker. Tasker sends an intent to my App, but it seems not to recieve it.

I read e.g. https://www.b4x.com/android/forum/threads/20103/#content and https://www.b4x.com/android/forum/threads/31136/#content.
I think I've done anything to recieve the broadcast, but when I trigger the intent with tasker, nothing happens. It seems I missed something relevant.

My manifest includes:
B4X:
AddReceiverText(WebSend, <intent-filter>
  <action android:name="de.helmutbender.setstatus.NEW_STATUS" />
   <category android:name="android.intent.category.DEFAULT" />
</intent-filter>)

My service WebSend includes:
B4X:
Sub Service_Start (StartingIntent As Intent)
	Log("Starting WebSend with " & StartingIntent.Action & " : " & StartingIntent.GetData)
	If StartingIntent.Action = "de.helmutbender.setstatus.NEW_STATUS" Then
		Dim s As String = StartingIntent.GetData
		Log("NEW_STATUS to " & s)
		If IsNumber(s) Then
			CallSubDelayed2(Main, "ChgStatus", s)
		Else
			Log(" => is not a number!")
		End If
	Else
		InitiateWebUpdate
	End If
End Sub

The service is called from Main to send the status update to a web server (InitiateWebUpdate), too.
When I trigger the Update from the App, it's working. When I send the intent from tasker, it doesn't log anything.

tasker has the following definition:
B4X:
Action: de.helmutbender.setstatus.NEW_STATUS
Type: Default
Data: [e.g.] 6
Target: broadcast receiver

What do I do wrong?
 

Creideiki

Active Member
Licensed User
Longtime User
Have you tried to remove the category?

Also add this line:
B4X:
SetReceiverAttribute(WebSend, android:exported, true)
Something I'm doing wrong.
I removed the <category> tag and added the SetReceiverAttribute. Still no reaction when triggering the task in tasker.
I changed the type of the task from 'default' to 'none', still no success.

Is there a tool with which one can debug broadcasts?
 
Upvote 0

Creideiki

Active Member
Licensed User
Longtime User
You can send an intent yourself from a different app with Phone.SendBroadcast (to test it).
OK. I set up a tiny app from scratch with

Manifest
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true"
  android:normalScreens="true"
  android:smallScreens="true"
  android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")
'End of default text.
AddReceiverText(Starter, <intent-filter>
  <action android:name="de.helmutbender.setstatus.NEW_STATUS" />
</intent-filter>)
SetReceiverAttribute(Starter, android:exported, true)

Main includes a button with
B4X:
Sub btISend_Click
   Dim myIntent As Intent
   myIntent.Initialize("de.helmutbender.setstatus.NEW_STATUS", "6")
   Dim p As Phone
   p.SendBroadcastIntent(myIntent)
   Log("IntentTester: Intent sent.")
End Sub

Starter has changed only one line
B4X:
Sub Service_Start (StartingIntent As Intent)
   Log("IntentTest starting with " & StartingIntent.Action & " : " & StartingIntent.GetData)

End Sub

I think, an app should be able to recieve it's own intents, shouldn't it?
Are there any permissions I should set?

BTW: The 'Intent sent' from the _Click is logged, the 'IntentTest starting with...' is not.
 

Attachments

  • IntentTest-0.1.0.zip
    7.8 KB · Views: 207
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Note that you shouldn't use the Starter service for this as it is a special service. Create a different service.

It will work if you remove the data component:
B4X:
myIntent.Initialize("de.helmutbender.setstatus.NEW_STATUS", "")

Or you can add a scheme to the intent filter:
B4X:
AddReceiverText(service1, <intent-filter>
  <action android:name="de.helmutbender.setstatus.NEW_STATUS" />
    <data android:scheme="helmut" />
</intent-filter>)

B4X:
myIntent.Initialize("de.helmutbender.setstatus.NEW_STATUS", "helmut://1")
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Creideiki

Active Member
Licensed User
Longtime User
Note that you shouldn't use the Starter service for this as it is a special service. Create a different service.
Why is it special? What should I do with it?
Or you can add a scheme to the intent filter:
B4X:
AddReceiverText(service1, <intent-filter>
  <action android:name="de.helmutbender.setstatus.NEW_STATUS" />
    <data android:scheme="helmut" />
</intent-filter>)

B4X:
myIntent.Initialize("de.helmutbender.setstatus.NEW_STATUS", "helmut://1")
I didn't know the 'data' has definitly to be an URI. Now it works. Thank you very much!

Am I right I could use en Extra as well for the data?
 
Upvote 0
Top