Starting a Service by Intent.

pmj

Member
Licensed User
Longtime User
Hello all,

I can't understand, why the following code does not work.
My service is not called when I put headphones in or out.

Manifest:

B4X:
AddReceiverText(headsetinout, 
<intent-filter>
   <action android:name="android.intent.action.HEADSET_PLUG" />
</intent-filter>)

AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true" 
    android:normalScreens="true" 
    android:smallScreens="true" 
    android:anyDensity="true"/>
   <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")

Servicemodule named "headsetinout":

B4X:
#Region  Service Attributes 
   #StartAtBoot: true
#End Region

Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
End Sub
Sub Service_Create
End Sub

Sub Service_Start (StartingIntent As Intent)

If StartingIntent.Action = "android.intent.action.HEADSET_PLUG" Then
'do something
End If
End Sub

Sub Service_Destroy
End Sub

Thank you in advance for your help.

Many friendly greetings from Per.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…