Java Code Examples for android.location.LocationManager#addGpsStatusListener()

The following examples show how to use android.location.LocationManager#addGpsStatusListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HomeActivity.java    From apollo-DuerOS with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initView();

    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mLocationManager.addGpsStatusListener(mGpsStatusListener);

    mWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(mReceiver, intentFilter);

    updateBlueToothStatus();
}
 
Example 2
Source File: HomeActivity.java    From apollo-DuerOS with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initView();

    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mLocationManager.addGpsStatusListener(mGpsStatusListener);

    mWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(mReceiver, intentFilter);

    updateBlueToothStatus();

    appInfoProvider = new AppInfoProvider(HomeActivity.this);
}
 
Example 3
Source File: LocationHelper.java    From MVPAndroidBootstrap with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize starting values and starting best location listeners
 *
 * @param ctx
 * @param result
 */
public void init(Context ctx, LocationResult result) {
    context = ctx;
    locationResult = result;

    myLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

    gps_enabled = (Boolean) myLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

    bestLocation = null;
    counts = 0;

    // turning on location updates
    myLocationManager.requestLocationUpdates("network", 0, 0, networkLocationListener);
    myLocationManager.requestLocationUpdates("gps", 0, 0, gpsLocationListener);
    myLocationManager.addGpsStatusListener(gpsStatusListener);

    // starting best location finder loop
    handler.postDelayed(showTime, iteration_timeout_step);
}
 
Example 4
Source File: LocationHelper.java    From RxAndroidBootstrap with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize starting values and starting best location listeners
 *
 * @param ctx
 * @param result
 */
public void init(Context ctx, LocationResult result) {
    context = ctx;
    locationResult = result;

    myLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

    gps_enabled = (Boolean) myLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

    bestLocation = null;
    counts = 0;

    // turning on location updates
    myLocationManager.requestLocationUpdates("network", 0, 0, networkLocationListener);
    myLocationManager.requestLocationUpdates("gps", 0, 0, gpsLocationListener);
    myLocationManager.addGpsStatusListener(gpsStatusListener);

    // starting best location finder loop
    handler.postDelayed(showTime, iteration_timeout_step);
}
 
Example 5
Source File: HomeActivity.java    From apollo-DuerOS with Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override
protected void onCreate(Bundle savedInstanceState) {
    ScreenAdapter.getInstance().adaptDensity(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initView();

    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (mLocationManager != null) {
        mLocationManager.addGpsStatusListener(mGpsStatusListener);
    }

    mWifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(mReceiver, intentFilter);

    updateBlueToothStatus();

    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager != null) {
        telephonyManager.listen(new PhoneStateListener() {
            @Override
            public void onServiceStateChanged(ServiceState serviceState) {
                super.onServiceStateChanged(serviceState);
                updateNetworkStatus();
            }
        }, PhoneStateListener.LISTEN_SERVICE_STATE);
    }
}
 
Example 6
Source File: GpsStatusService.java    From BackPackTrackII with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    Log.i(TAG, "Requesting GPS status updates");
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(GpsStatusService.this);
    SharedPreferences.Editor editor = prefs.edit();
    editor.remove(SettingsFragment.PREF_SATS_FIXED);
    editor.remove(SettingsFragment.PREF_SATS_VISIBLE);
    editor.apply();
    LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
    lm.addGpsStatusListener(mGpsStatusListener);
}
 
Example 7
Source File: LocationService.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
private void connect() {
    logger.debug("connect()");
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (mLocationManager != null) {
        mLastLocationMillis = -SKIP_INITIAL_LOCATIONS;
        mContinuous = false;
        mJustStarted = true;
        if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            mLocationManager.addGpsStatusListener(this);
            try {
                mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, LOCATION_DELAY, 0, this);
                //mLocationManager.addNmeaListener(this);
                mLocationsEnabled = true;
                logger.debug("Gps provider set");
            } catch (IllegalArgumentException e) {
                logger.warn("Cannot set gps provider, likely no gps on device");
            }
        } else {
            logger.error("Missing ACCESS_FINE_LOCATION permission");
        }
    }
    if (enableMockLocations && BuildConfig.DEBUG) {
        mMockLocationTicker = 0;
        mMockCallback.post(mSendMockLocation);
        mLocationsEnabled = true;
    }
}
 
Example 8
Source File: GpsServices.java    From SpeedMeter with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreate() {

    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    contentIntent = PendingIntent.getActivity(
            this, 0, notificationIntent, 0);

    updateNotification(false);

    mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    mLocationManager.addGpsStatusListener( this);
    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 0, this);
}
 
Example 9
Source File: DiagnosticsActivity.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
public void onResume() {
    super.onResume();
    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    try {
        lm.addGpsStatusListener(this);
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
    } catch (SecurityException e) {
    } catch (RuntimeException r) {
    }
}
 
Example 10
Source File: LocationService.java    From Androzic with GNU General Public License v3.0 5 votes vote down vote up
private void connect()
{
	locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
	if (locationManager != null)
	{
		lastLocationMillis = 0;
		pause = 1;
		isContinous = false;
		justStarted = true;
		smoothSpeed = 0.0f;
		avgSpeed = 0.0f;
		locationManager.addGpsStatusListener(this);
		try
		{
			locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
			locationManager.addNmeaListener(this);
			Log.d(TAG, "Gps provider set");
		}
		catch (IllegalArgumentException e)
		{
			Log.d(TAG, "Cannot set gps provider, likely no gps on device");
		}
		startForeground(NOTIFICATION_ID, getNotification());
	}
	if (enableMockLocations)
	{
		updateProvider(LocationManager.GPS_PROVIDER, true);
		mockCallback.post(sendMockLocation);
	}
}