android.location.LocationManager.addGpsStatusListener()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(166)

本文整理了Java中android.location.LocationManager.addGpsStatusListener()方法的一些代码示例,展示了LocationManager.addGpsStatusListener()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocationManager.addGpsStatusListener()方法的具体详情如下:
包路径:android.location.LocationManager
类名称:LocationManager
方法名:addGpsStatusListener

LocationManager.addGpsStatusListener介绍

暂无

代码示例

代码示例来源:origin: robolectric/robolectric

private Listener addGpsListenerToLocationManager() {
 Listener listener = new TestGpsListener();
 locationManager.addGpsStatusListener(listener);
 return listener;
}

代码示例来源:origin: stackoverflow.com

myLocationManager.addGpsStatusListener(gpsStatusListener);

代码示例来源:origin: openbmap/radiocells-scanner-android

/**
 * Request GPS update notification
 */
private void enableUpdates() {
  if (lmgr != null) {
    try {
      lmgr.addGpsStatusListener(this);
      lmgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, gpsLoggingInterval, 0, this);
    } catch (SecurityException e) {
      Log.e(TAG, "You denied GPS permission, so this app won't work");
    }
  }
}

代码示例来源:origin: hzw1199/AndroidGpsStatus

/**
 * Register GPS Status Listener, must check for permission of ACCESS_FINE_LOCATION first!
 */
public void register() {
  unRegister();
  if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
    return;
  }
  locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
  locationManager.addGpsStatusListener(listener);
}

代码示例来源:origin: Phantast/smartnavi

public void starteAutocorrect() {
  if (autoCorrectSuccess) {
    autoCorrectSuccess = false;
  } else if (additionalSecondsAutocorrect <= 30) {
    additionalSecondsAutocorrect = additionalSecondsAutocorrect + 7;
    allowedErrorGps = allowedErrorGps + 8;
    if (BuildConfig.debug)
      Log.i("Location-Status", "Time for request:" + additionalSecondsAutocorrect + " and allowed Error: " + allowedErrorGps);
  }
  try {
    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
        100, 0, gpsAutocorrectLocationListener);
    mHandler.postDelayed(autoStopTask,
        10000 + additionalSecondsAutocorrect * 1000);
    mHandler.postDelayed(satelitesInRangeTest, 10000);
    mLocationManager.addGpsStatusListener(mGpsStatusListener);
    giveGpsMoreTime = true;
  } catch (SecurityException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: flyingrub/SpeedMeter

@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);
}

代码示例来源:origin: BasicAirData/GPSLogger

public void updateGPSLocationFrequency () {
  if (isGPSLocationUpdatesActive
      && (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)) {
    mlocManager.removeGpsStatusListener(this);
    mlocManager.removeUpdates(this);
    StabilizingSamples = (int) Math.ceil(STABILIZERVALUE / prefGPSupdatefrequency);
    mlocManager.addGpsStatusListener(this);
    mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, prefGPSupdatefrequency, 0, this);
  }
}

代码示例来源:origin: labexp/osmtracker-android

public void requestLocationUpdates(boolean request) {
  if (request) {
    if (ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
      lmgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
      lmgr.addGpsStatusListener(this);
    }
    else {
        ActivityCompat.requestPermissions((Activity) activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
            REQUEST_CODE_GPS_PERMISSIONS);
      }
  } else {
    lmgr.removeUpdates(this);
    lmgr.removeGpsStatusListener(this);
  }
}

代码示例来源:origin: Car-eye-team/Car-eye-device

/**
 * GPS定位初始化
 */
public void initGPS(){
  try {
    lManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    //监听状态
    lManager.addGpsStatusListener(listener);
    //绑定监听,有4个参数   
    //参数1,设备:有GPS_PROVIDER和NETWORK_PROVIDER两种
    //参数2,位置信息更新周期,单位毫秒   
    //参数3,位置变化最小距离:当位置距离变化超过此值时,将更新位置信息   
    //参数4,监听   
    //备注:参数2和3,如果参数3不为0,则以参数3为准;参数3为0,则通过时间来定时更新;两者为0,则随时刷新   
    // 1秒更新一次,或最小位移变化超过1米更新一次;
    //注意:此处更新准确度非常低,推荐在service里面启动一个Thread,在run中sleep(10000);然后执行handler.sendMessage(),更新位置
    lManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);			
  } catch (Exception e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: BasicAirData/GPSLogger

public void setGPSLocationUpdates (boolean state) {
  // Request permissions = https://developer.android.com/training/permissions/requesting.html
  if (!state && !getRecording() && isGPSLocationUpdatesActive
      && (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)) {
    GPSStatus = GPS_SEARCHING;
    mlocManager.removeGpsStatusListener(this);
    mlocManager.removeUpdates(this);
    isGPSLocationUpdatesActive = false;
  }
  if (state && !isGPSLocationUpdatesActive
      && (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)) {
    mlocManager.addGpsStatusListener(this);
    mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, prefGPSupdatefrequency, 0, this); // Requires Location update
    isGPSLocationUpdatesActive = true;
    StabilizingSamples = (int) Math.ceil(STABILIZERVALUE / prefGPSupdatefrequency);
  }
}

代码示例来源:origin: stackoverflow.com

public void beginMonitoringLocation(int minDistance) {
     IntentFilter filter = new IntentFilter();
     filter.addAction(MainActivity.LOCATION_UPDATE_ACTION);
     this.mContext.registerReceiver(this.locationReceiver, filter);
     LocationManager mLocationManager = (LocationManager) this.mContext.getSystemService(Context.LOCATION_SERVICE);
     mLocationManager.addGpsStatusListener(this);
     boolean enabled =  mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
     if (!enabled) {
       Log.e("LocationManager", "GPS not enabled!!!!");
     } 
     LocationProvider provider = mLocationManager.getProvider(LocationManager.GPS_PROVIDER); // GET THE BEST PROVIDER FOR OUR LOCATION
     Log.d("LocationManager:","Location Provider:"+provider);
     if ( provider == null ) {
       Log.e( "LocationManager", "No location provider found!" );
       return;
     }
     final int locationUpdateRC=0;
     int flags = 0;
     Intent intent = new Intent(MainActivity.LOCATION_UPDATE_ACTION); 
     PendingIntent pendingIntent = PendingIntent.getBroadcast(this.mContext, locationUpdateRC, intent, flags); 
     // PENDING INTENT TO BE FIRED WHEN THE LOCATIONMANAGER RECEIVES LOCATION UPDATE.
     // THIS PENDING INTENT IS CAUGHT BY OUR BROADCAST RECEIVER
     mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,minDistance,pendingIntent);
     this._monitoringLocation = true;
 }

代码示例来源:origin: FussenYu/MVP_Project

private void registerGPSListener() {
  if (locationManager == null) {
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  }
  //获取最佳位置定位方式
  locationManager.getBestProvider(createFineCriteria(), true);
  locationManager.addGpsStatusListener(gpsStatusListener);
}

代码示例来源:origin: pires/android-obd-reader

private boolean gpsInit() {
  mLocService = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  if (mLocService != null) {
    mLocProvider = mLocService.getProvider(LocationManager.GPS_PROVIDER);
    if (mLocProvider != null) {
      mLocService.addGpsStatusListener(this);
      if (mLocService.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        gpsStatusTextView.setText(getString(R.string.status_gps_ready));
        return true;
      }
    }
  }
  gpsStatusTextView.setText(getString(R.string.status_gps_no_support));
  showDialog(NO_GPS_SUPPORT);
  Log.e(TAG, "Unable to get GPS PROVIDER");
  // todo disable gps controls into Preferences
  return false;
}

代码示例来源:origin: ApolloAuto/apollo-DuerOS

@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();
}

代码示例来源:origin: ApolloAuto/apollo-DuerOS

@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);
}

代码示例来源:origin: flyingrub/SpeedMeter

@Override
protected void onResume() {
  super.onResume();
  firstfix = true;
  if (!data.isRunning()){
    Gson gson = new Gson();
    String json = sharedPreferences.getString("data", "");
    data = gson.fromJson(json, Data.class);
  }
  if (data == null){
    data = new Data(onGpsServiceUpdate);
  }else{
    data.setOnGpsServiceUpdate(onGpsServiceUpdate);
  }
  if (mLocationManager.getAllProviders().indexOf(LocationManager.GPS_PROVIDER) >= 0) {
    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 0, this);
  } else {
    Log.w("MainActivity", "No GPS location provider found. GPS data display will not be available.");
  }
  if (!mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
    showGpsDisabledDialog();
  }
  mLocationManager.addGpsStatusListener(this);
}

代码示例来源:origin: mizutori/AndroidLocationStarterKit

Integer gpsFreqInDistance = 5;  // in meters
locationManager.addGpsStatusListener(this);

代码示例来源:origin: stackoverflow.com

mGPSLocationListener = new GPSLocationListener();
manager.addGpsStatusListener(mGPSStatusListener);
mTimerTask = new LocTimerTask(LocationManager.GPS_PROVIDER);

代码示例来源:origin: ApolloAuto/apollo-DuerOS

@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);
  }
}

代码示例来源:origin: wiglenet/wigle-wifi-wardriving

state.gpsListener.setMapListener(MappingFragment.STATIC_LOCATION_LISTENER);
try {
  locationManager.addGpsStatusListener(state.gpsListener);
} catch (final SecurityException ex) {
  info("Security exception adding status listener: " + ex, ex);

相关文章