执行code,当用户改变在Android的静音模式静音、模式、用户、code

2023-09-04 23:27:22 作者:Luminary 发光体

我使用的服务。在该服务的用户更改为静音模式,即只要用户更改到静音模式,我的code需要得到执行时,我的code应该得到执行。

I'm using a service. In that service my code should get executed when the user changes to silent mode, i.e. as soon as the user changes to silent mode, my code needs to get executed.

我怎样才能做到这一点?

How can I do this?

推荐答案

您不想使用的服务。相反,你要使用 BroadcastReciever 的过滤器的android.media。 RINGER_MODE_CHANGED意图。

You don't want use a service. Instead you want to use a BroadcastReciever that filters for the android.media.RINGER_MODE_CHANGED Intent.

您可能想看看这项目因为它涉及的是手机被灭口。它可能有一些源$ C ​​$ C,这将是对你有用。

You might want to take a look at this project as it deals with the phone being silenced. It probably has some source code that will be useful to you.