任何方法来检测音量键presses或体积的改变与Android服务?音量、方法来、体积、presses

2023-09-05 02:52:42 作者:把心熬成铁

一些Android应用生成通知时,该设备的体积变化,部分锁定卷。对于我的生活,我不能找出如何这样做了。请,有人可以帮我提供一个例子吗?

Some Android apps generate a notification when the device's volume changes and some lock the volume. For the life of me, I cannot find out how that's done. Please, can someone help me by providing an example?

推荐答案

有没有广播事件检测量的变化,但也许你可以每隔一两秒钟检查音量是什么 getStreamVolume ,如果你需要在一个特定的音量锁定,每隔一两秒钟的使用: setStreamVolume

There is no Broadcast Action to detect volume changes, but you could maybe every second or two check what the volume is with getStreamVolume and if you need to lock it at a specific volume, every second or two use: setStreamVolume

检查 http://developer.android.com/reference/android/media /AudioManager.htm 获取更多的信息。

您可以使用AlarmManager类或处理程序来检查卷每秒左右。

You could use the AlarmManager class or a handler to check the volume every second or so.

如果它是一个活动,您可以覆盖的onkeydown 来检测键presses。请参见 http://developer.android.com/reference/android/view/View。 HTML

If it's an activity, you can override onKeyDown to detect key presses. See http://developer.android.com/reference/android/view/View.html