public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().matches("android.location.PROVIDERS_CHANGED")) {
Toast.makeText(context, "in android.location.PROVIDERS_CHANGED",
Toast.LENGTH_SHORT).show();
Intent pushIntent = new Intent(context, LocalService.class);
context.startService(pushIntent);
} else {
Toast.makeText(context, "not in android.location.PROVIDERS_CHANGED",
Toast.LENGTH_SHORT).show();
Intent pushIntent = new Intent(context, LocalService.class);
context.startService(pushIntent);
}
}
@Override
public void onLocationChanged(Location arg0) {
}
}
Run Code Online (Sandbox Code Playgroud)
在我的应用程序中,我需要在打开/关闭gps时触发广播接收器.调查此事并建议在app中实施最好的一个.
我通过使用侦听PROVIDERS_CHANGED操作的BroadcastReceiver尝试了一种方法,但这只会告诉我何时打开/关闭位置设置.我想知道什么时候使用位置服务来获取任何应用程序的位置.我不需要知道哪个应用程序正在执行它,我不关心位置本身.我只想知道某个应用程序试图获取某个位置,以及何时停止这样做.这可能吗?