Android Question Intercept KeyPress Headset from a service

Aviles

Member
Licensed User
I'm trying to intercept the pulsation 79 (headset button) from a service with a intent
but I manage to make it work.

could help me please
 

Aviles

Member
Licensed User
B4X:
'Service: AlarmService
'previously started from main activity

Sub Process_Globals
    Dim br As BroadCastReceiver
End Sub
Sub Service_Create
    br.Initialize("BroadcastReceiver")
End Sub

Sub Service_Start (StartingIntent As Intent)
   LogColor("»receiver [Iniciado]",Colors.Red)
   br.addAction("android.intent.action.MEDIA_BUTTON")
   br.SetPriority(2147483647)
   br.registerReceiver("")
End Sub

Sub Service_Destroy
    LogColor("»receiver [Terminado]",Colors.Red)
End Sub

Sub BroadcastReceiver_OnReceive (Action As String, Extras As Object)
    LogColor("»receiver [RECIBIDO »action: "&Action,Colors.Red)
   br.AbortBroadcast
End Sub
B4X:
'MANIFEST

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.
AddPermission(android.permission.MODIFY_AUDIO_SETTINGS)
AddReceiverText(AlarmService,
<intent-filter>
    <action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>)
the only thing I need is to intercept the headset button,
 

Aviles

Member
Licensed User
yes of course, when i start main activity started the service.
but not catch the pressed button

but not intercept the pressed button
 
Top