Thks, Erel. But,.. its not working for me. I need to intercept button in service.Use a static intent filter: http://www.b4x.com/android/forum/threads/intercept-volume-button-press.28179/#post-163378
'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
My Manifest looks so:Have you added the manifest editor code?
Add Log(StartingIntent) to check whether an intent was received.
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.
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.The solution in this link is the same as the one you implemented. Just add androidriority="2147483647" to the intent filter.
OK. Thks.Static intents cannot be removed. However you can decide in the service what you want to do. You can for example use IsPaused(Main) and if it is paused don't do anything.