Android Question Strange problem capturing volume keys on Galaxy S4

Kevin

Well-Known Member
Licensed User
I don't know for sure that this is specific to the Galaxy S4 or not, but 2 of 4 people I've talked to with an S4 have reported this problem:

My app intercepts the volume keys being pressed and then sends an intent. Depending on some circumstances that intent either starts an invisible activity in another app or starts a service in another app.

There is a button ("view") in the app that the user can press that calls the exact same sub as in my Activity_Keypress sub. However, apparently that works fine and they only get a crash (Sorry... APP NAME needs to close) if using the volume rocker keys on the phone.

The code does limit how often the intent will be sent, but apparently this crash happens even if only pressing the volume rocker button one single time.

Any ideas? Seems strange!


B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
    If KeyCode = KeyCodes.KEYCODE_MENU Then
        If CurrentScreen = "Setup" OR CurrentScreen = "ManualAdd" OR CurrentScreen = "QS" OR CurrentScreen = "FAV2" OR CurrentScreen = "Macro2" Then
            Return True ' Don't allow user to press menu key while in these screens
        End If
    End If

    If KeyCode = KeyCodes.KEYCODE_MENU Then ' Use the new custom menus
        OpenMenu
        Return True
    End If


' ============ THIS IS THE PROBLEM AREA =============
' LastVolumeHardKeySentTime is declared as LONG in the Process_Globals section
    If KeyCode = KeyCodes.KEYCODE_VOLUME_UP Then
    'Log("Vol Up")
        If DateTime.Now - LastVolumeHardKeySentTime > 500 Then   
            LastVolumeHardKeySentTime = DateTime.Now
            Common.SendAVCommand ("4")
        End If
    Return True
  End If
   
    If KeyCode = KeyCodes.KEYCODE_VOLUME_DOWN Then
    'Log("Vol Down")
        If DateTime.Now - LastVolumeHardKeySentTime > 500 Then   
            LastVolumeHardKeySentTime = DateTime.Now       
          Common.SendAVCommand ("5")
        End If
    Return True
  End If
' ================================================


    If KeyCode = KeyCodes.KEYCODE_BACK Then
        CallSubDelayed(Me, "HandleBackKey")
    Return True
    End If

    Return False

End Sub
 

Kevin

Well-Known Member
Licensed User
Yes, unfortunately I do not have access to the actual error message or crash reports. Of the two people this happens to, one never wrote to me (left comment) and the other says he sent a crash report at my request but I do not see it in my developer console.

I thought about the issue with the Exit button that was fixed with CallSubDelayed and wondered if this could be a related issue. Do you think there is a possibility of this? Hopefully I will get to see a crash log soon.
 
Upvote 0

Kevin

Well-Known Member
Licensed User
There is no modal dialog that would or could be shown as a result of that. I imagine there could be a slight delay before the other sub is done executing (Common.SendAVCommand) but it shouldn't be more than a couple hundred milliseconds.

I still haven't seen a crash report... I don't understand why since the one person said he sent it. Whatever it is, it is apparently only happening when calling that sub from the volume key button press event.
 
Upvote 0
Top