Android Question Headset button

stari

Active Member
Licensed User
Longtime User
I try to detect, if button on Headset is active or not. But i can get any signal from button. What i make wrong ?
 

Attachments

  • BCR.zip
    7.7 KB · Views: 384

stari

Active Member
Licensed User
Longtime User
I try with this code:
B4X:
'Service module

Sub Process_Globals

       Dim Broadcast As BroadCastReceiver

End Sub

Sub Service_Create
   
    Log("Created Service")
       
   
End Sub

Sub Service_Start(StartingIntent As Intent)
   
      
   
Dim prevVol As Int
Dim curVol As Int
Dim volType As Int

If (StartingIntent.HasExtra("android.media.EXTRA_PREV_VOLUME_STREAM_VALUE") OR StartingIntent.HasExtra("android.media.EXTRA_VOLUME_STREAM_VALUE") OR StartingIntent.Action = "android.media.VOLUME_CHANGED_ACTION") Then
      'prevVol = StartingIntent.GetExtra("android.media.EXTRA_PREV_VOLUME_STREAM_VALUE")
      'curVol = StartingIntent.GetExtra("android.media.EXTRA_VOLUME_STREAM_VALUE")
      'volType = StartingIntent.GetExtra("android.media.EXTRA_VOLUME_STREAM_TYPE")

      Log("OK, received")
End If

     If (StartingIntent.HasExtra("android.intent.ACTION_MEDIA_BUTTON")) Then
        Log("OK, received")
    End If
   
    Log("OK, Service started " & StartingIntent)
End Sub

Sub BroadcastReceiver_OnReceive(Action As String, Extras As Object)
    ToastMessageShow(Action,False)
    Log(Action)
       
End Sub

Sub Service_Destroy

End Sub

Not working. From Activity i can read MEDIA BUTTON as "79". What i make wrong ?
 
Upvote 0

stari

Active Member
Licensed User
Longtime User
Have you added the manifest editor code?

Add Log(StartingIntent) to check whether an intent was received.
My Manifest looks so:
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="4" />
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
AddPermission(android.permission.RECEIVE_SMS)

AddReceiverText(Receiver,
<intent-filter>
    <action android:name="net.work.box.controller.receivers.RemoteControlReceiver" />
</intent-filter>)

AddReceiverText(Receiver,
<intent-filter>
    <action android:name="android.intenet.AUDIO_BECOMING_NOISY" />
</intent-filter>)

AddReceiverText(Receiver,
<intent-filter>
    <action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>)
 
AddReceiverText(Receiver, <intent-filter>
   <action android:name="android.media.VOLUME_CHANGED_ACTION" />
    </intent-filter>)

'End of default text.

I receive, when Headphones are pluged/unpluged, but no action if the button is pressed.
Also i have Log(StaringIntenet). Nothing recieved, when button is pressed.
Java example i found here:
http://stackoverflow.com/questions/...cept-button-presses-on-the-headset-in-android
 
Upvote 0

stari

Active Member
Licensed User
Longtime User
The solution in this link is the same as the one you implemented. Just add android:priority="2147483647" to the intent filter.
OK, all working OK. My mistake was, that i have tested on my Samsung Galaxy Tab. But, on tablets this don't work. Thks Erel for cooperation.
 
Upvote 0

stari

Active Member
Licensed User
Longtime User
Hello, mr. Erel. all OK, only now i wish to close application and i wish, that static intent is no more active. I can't find solution, only uninstall was helpful. Any sugestion ?
 
Upvote 0

stari

Active Member
Licensed User
Longtime User
Hi,
Erel thks for help. I have another problem with this aplication.
All thinks are working OK, but not on Samsung S3 and S4 with Android 4.3.
My test aplication is here, if you have any suggestion, what to do.
Thank you.
 

Attachments

  • PHC.zip
    11.7 KB · Views: 424
Upvote 0
Top