任何方法来检测音量键presses或体积的改变与Android服务? [英] any way to detect volume key presses or volume changes with android service?

查看:177
本文介绍了任何方法来检测音量键presses或体积的改变与Android服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些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

这篇关于任何方法来检测音量键presses或体积的改变与Android服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆