gpt4 book ai didi

android - 检测 Android 手机中的 GPS 开/关开关

转载 作者:IT老高 更新时间:2023-10-28 21:51:50 25 4
gpt4 key购买 nike

我想检测用户何时打开或关闭 Android 手机的 GPS 设置。这意味着当用户打开/关闭 GPS 卫星或通过接入点等进行检测时。

最佳答案

我发现最好的方法是附加到

<action android:name="android.location.PROVIDERS_CHANGED" />

Intent 。

例如:

<receiver android:name=".gps.GpsLocationReceiver">
<intent-filter>
<action android:name="android.location.PROVIDERS_CHANGED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>

然后在代码中:

public class GpsLocationReceiver extends BroadcastReceiver implements LocationListener 
...

@Override
public void onReceive(Context context, Intent intent)
{
if (intent.getAction().matches("android.location.PROVIDERS_CHANGED"))
{
// react on GPS provider change action
}
}

关于android - 检测 Android 手机中的 GPS 开/关开关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6368286/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com