Example usage for android.location LocationManager MODE_CHANGED_ACTION

List of usage examples for android.location LocationManager MODE_CHANGED_ACTION

Introduction

In this page you can find the example usage for android.location LocationManager MODE_CHANGED_ACTION.

Prototype

String MODE_CHANGED_ACTION

To view the source code for android.location LocationManager MODE_CHANGED_ACTION.

Click Source Link

Document

Broadcast intent action when android.provider.Settings.Secure#LOCATION_MODE changes.

Usage

From source file:com.tenforwardconsulting.cordova.bgloc.BackgroundGeolocationPlugin.java

public Intent registerLocationModeChangeReceiver() {
    if (isLocationModeChangeReceiverRegistered) {
        return null;
    }/*w ww  . j a  va 2 s .co m*/

    isLocationModeChangeReceiverRegistered = true;
    return getContext().registerReceiver(locationModeChangeReceiver,
            new IntentFilter(LocationManager.MODE_CHANGED_ACTION));
}

From source file:com.landenlabs.all_devtool.GpsFragment.java

@SuppressWarnings("deprecation")
@Override/*ww  w  .j av a2  s  . c o m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);

    View rootView = inflater.inflate(R.layout.gps_tab, container, false);
    m_statusIcon = Ui.viewById(rootView, R.id.gpsStatus);
    m_statusIcon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
        }
    });

    Ui.viewById(rootView, R.id.gps_clear).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            clearList();
        }
    });

    m_list.clear();
    // ---- Get UI components  ----
    for (int idx = 0; idx != s_maxRows; idx++)
        m_list.add(null);
    m_list.set(s_providersRow, new GpsInfo(new GpsItem("Providers")));
    m_list.set(s_lastUpdateRow, new GpsInfo(new GpsItem("Last Update")));
    m_list.set(s_detailRow, new GpsInfo(new GpsItem("Detail History")));

    m_listView = Ui.viewById(rootView, R.id.gpsListView);
    final GpsArrayAdapter adapter = new GpsArrayAdapter(this.getActivity());
    m_listView.setAdapter(adapter);

    // ---- Setup GPS ----
    m_locMgr = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);

    m_gpsTv = Ui.viewById(rootView, R.id.gps);
    if (isGooglePlayServicesAvailable()) {
        m_locationRequest = new LocationRequest();
        m_locationRequest.setInterval(GPS_INTERVAL);
        m_locationRequest.setFastestInterval(GPS_FASTEST_INTERVAL);
        // Priority needs to match permissions.
        //  Use LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY with
        // <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
        //  Use LocationRequest.PRIORITY_HIGH_ACCURACY with
        // <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
        m_locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);

        m_googleApiClient = new GoogleApiClient.Builder(this.getActivity()).addApi(LocationServices.API)
                .addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();

        m_gpsTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                m_gpsMonitor = !m_gpsMonitor;
                view.setSelected(m_gpsMonitor);
                addMsgToDetailRow(s_colorMsg, m_gpsMonitor ? "Start Monitor" : "Stop Monitor");
                showProviders();
            }
        });

    } else {
        m_gpsTv.setText("Need Google Play Service");
    }

    if (ActivityCompat.checkSelfPermission(getContext(),
            Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        m_locMgr.addGpsStatusListener(this);
    }

    /*  http://stackoverflow.com/questions/11398732/how-do-i-receive-the-system-broadcast-when-gps-status-has-changed
    <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=".GpsReceiver">
    <intent-filter>
         <action android:name="android.location.GPS_ENABLED_CHANGE" />
         <action android:name="android.location.PROVIDERS_CHANGED" />
    </intent-filter>
    </receiver>
    */
    // GpsReceiver m_gpsReceiver = new GpsReceiver();
    m_intentFilter.addAction(GpsReceiver.GPS_ENABLED_CHANGE_ACTION);
    if (Build.VERSION.SDK_INT >= 19) {
        m_intentFilter.addAction(LocationManager.MODE_CHANGED_ACTION);
    }
    m_intentFilter.addAction(GpsReceiver.GPS_FIX_CHANGE_ACTION);
    m_intentFilter.addAction(LocationManager.PROVIDERS_CHANGED_ACTION);

    showProviders();
    // TODO - get available providers
    getCheckBox(rootView, R.id.gpsFuseCb, FUSED_PROVIDER);
    getCheckBox(rootView, R.id.gpsGPSCb, LocationManager.GPS_PROVIDER);
    getCheckBox(rootView, R.id.gpsNetwkCb, LocationManager.NETWORK_PROVIDER);
    getCheckBox(rootView, R.id.gpsLowPwrCb, LocationManager.PASSIVE_PROVIDER);
    getCheckBox(rootView, R.id.gpsStatusCb, STATUS_CB);

    for (CheckBox cb : m_providersCb.values()) {
        cb.setOnClickListener(this);
    }
    initLastUpdate();

    // Expand All
    for (int idx = 0; idx != s_maxRows; idx++)
        m_listView.expandGroup(idx);

    return rootView;
}

From source file:com.tenforwardconsulting.cordova.BackgroundGeolocationPlugin.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private Intent registerLocationModeChangeReceiver(CallbackContext callbackContext) {
    if (locationModeChangeCallbackContext != null) {
        unregisterLocationModeChangeReceiver();
    }/*from   www.  java2 s.  c  o  m*/
    locationModeChangeCallbackContext = callbackContext;
    return getContext().registerReceiver(locationModeChangeReceiver,
            new IntentFilter(LocationManager.MODE_CHANGED_ACTION));
}