Hi All,
I would want to be able to access to the physical volume buttons from a locked device...
I already succeed to access to a pseudo state of the volume buttons from a service using this code:
in the manifest added an intent to my service:
and my Testservice code is:
When the phone is unlocked, the background service catches the intent and performs the correct action when volume is changed but when locked, nothing ... except if the media player is reading a mp3, in that case in addition to change the volume, the vibrations are present
Do you know what to add to allow my app to act as a media player with volume buttons remaining active even when locked ?
thanks
Alain
I would want to be able to access to the physical volume buttons from a locked device...
I already succeed to access to a pseudo state of the volume buttons from a service using this code:
in the manifest added an intent to my service:
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14"/>
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL"/> '<<<<<<<< USELESS
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
AddReceiverText(TestService, <intent-filter>
<action android:name="android.media.VOLUME_CHANGED_ACTION" />
</intent-filter>)
and my Testservice code is:
B4X:
Sub Process_Globals
Dim PE As PhoneEvents
Dim Vibrate As PhoneVibrate ' For phone vibration
End Sub
Sub Service_Create
PE.Initialize("PE")
End Sub
Sub Service_Start(startingIntent As Intent)
Dim mystring = startingIntent.ExtrasToString
Log(mystring)
Dim volume As Int = startingIntent.GetExtra("android.media.EXTRA_VOLUME_STREAM_VALUE")
Dim volume_prec As Int = startingIntent.GetExtra("android.media.EXTRA_PREV_VOLUME_STREAM_VALUE")
Dim delta As Int
delta = volume - volume_prec
If delta > 0 Then
Vibrate.Vibrate(100)
Else If delta <0 Then
Vibrate.Vibrate(50)
Else If (delta = 0 AND volume = 0) Then
Vibrate.Vibrate(50)
Else If (delta = 0 AND volume = 7) Then
Vibrate.Vibrate(100)
End If
End Sub
When the phone is unlocked, the background service catches the intent and performs the correct action when volume is changed but when locked, nothing ... except if the media player is reading a mp3, in that case in addition to change the volume, the vibrations are present
Do you know what to add to allow my app to act as a media player with volume buttons remaining active even when locked ?
thanks
Alain