Android Question Intercept KeyPress Headset from a service

Discussion in 'Android Questions' started by Aviles, Jun 5, 2015.

  1. Aviles

    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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Can you post your code (including the manifest editor code)?
     
  3. Aviles

    Aviles Member Licensed User

    Code:
    '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
    Code:
    '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,
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Have you started the service? Otherwise the dynamic intent filter will not work.
     
  5. Aviles

    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
     
  6. Erel

    Erel Administrator Staff Member Licensed User

Loading...