相关疑难解决方法(0)

打开/关闭gps时如何触发广播接收器?

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中实施最好的一个.

gps android broadcastreceiver location-provider

42
推荐指数
3
解决办法
3万
查看次数

在设置中收听位置访问禁用/启用

在Android操作系统中,在" 设置 " - >" 位置服务 "中,有一个名为" 访问我的位置 " 的切换按钮,可用于禁用和启用应用程序的位置信息访问.

目前,我正在开发一个位置服务应用程序.我想知道,我怎么能在我的Android项目中听这个设置?当用户禁用或启用" 访问我的位置 " 时,是否有任何广播接收器可以立即知道?

如果没有任何广播接收器,我如何在Android项目中听取此更改?

android broadcastreceiver android-intent android-broadcast

8
推荐指数
2
解决办法
3160
查看次数

当GPS状态发生变化时,如何接收系统广播?

我在下面编写了代码,但它没有用.有谁能够帮我?我只想被动地接收GPS状态变化,而不是主动询问.节电是最重要的.

没有消息输出.

package com.sharelbs.lbs.service;  
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class GPStStatusReceiver extends BroadcastReceiver {
  public static final String GPS_ENABLED_CHANGE_ACTION = "android.location.GPS_ENABLED_CHANGE";
  @Override
    public void onReceive(Context context, Intent intent) {
      Log.d("---------log--------","GPS Status onReceive");
      if(intent.getAction().equals(GPS_ENABLED_CHANGE_ACTION)){
        Log.d("---------log--------","GPS Status Changed");
        startMyProgram();
      }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的Manifest.xml:

<uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<receiver android:name=".service.GPStStatusReceiver"> 
  <intent-filter> 
    <action android:name="android.location.GPS_ENABLED_CHANGE" /> 
  </intent-filter> 
</receiver>
Run Code Online (Sandbox Code Playgroud)

gps android

2
推荐指数
1
解决办法
8643
查看次数