Reputation: 2827
I doubt it is, but is it possible to detect if the volume button is pressed, by jQuery or any of the web languages?
I want to do some basic user testing, to investigate by which way it's best to call a certain function; either a gesture or a hardware button. I't not a problem to call a function based on a touch gesture, but calling a function based on pressing a hardware button is a bit more difficult.
As I got both an Android phone and iPhone here, it doesn't matter if it only works on one of both devices.
Since I can't write C++, this language isn't an option. Even though this language does support hardware button detection
What I want to create
It's the most basic version of a test: I want to see by which way people would like to switch from round to squared display.
There is a simple round object in the center and it should transform to a square, based on any of the following gestures: A hardware button press (volume), pinch, pinch-out, 4-finger pinch out, 2 finger swipe down.
Upvotes: 0
Views: 1979
Reputation: 1036
Short answer: If you're running this in a mobile browser (e.g. Safari or Chrome), you don't have access to the volume buttons.
Explanation: JQuery relies on JavaScript which relies on a browser, webview (for native apps), or a node.js server (irrelevant for you). Webviews tend to be like a browser but with fewer features. The main browsers out there do not provide access to the volume buttons. Therefore, jQuery isn't going to solve this for you.
Solution: You're going to need a native app if you really want to use the volume buttons. On Android, apps are written in Kotlin (based on Java). On iOS, they're written in Swift (or Objective-C). If you know only one or none of those languages, there are cross-platform tools that'll let you write the app once and deploy to both platforms. Depending on the level of control you want, you could use a tool that provides a unified framework or go for a fancy drag-and-drop builder. There are TONS of options out there.
Extra: Looking at your history, it seems like you're a "web" guy. If you just want to use jQuery/JavaScript for the convenience, you could create a simple native app that basically does just two things: 1) Load your webapp, and 2) Provide an API to the webapp for accessing the volume buttons. This topic will get you moving in that direction: Calling android native APIs from javascript functions of embedded WebView
I encourage other web folks to hack around a little on mobile platforms. You never know when a base level understanding could come in handy.
Upvotes: 5