示例#1
0
 /** Is called when the application is resumed */
 @Override
 public void onResume() {
   super.onResume();
   locationListener.startLocationUpdate(); // Start the location listener again
   getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // Keep screen on
   if (isAlive) {
     sensorDataObservable.Resume(); // Resume the sensor observer
     frequencyListener.run();
   }
 }
示例#2
0
 /** Is called when the application is paused */
 @Override
 public void onPause() {
   super.onPause();
   locationListener.stopLocationUpdate(); // Pauses the lcoation listener
   getWindow()
       .clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // Disable screen lock on
   if (isAlive) {
     frequencyListener.pause();
     sensorDataObservable.Pause(); // Pauses the sensor observer
   }
 }
示例#3
0
  /** Is called when the permission request is answered */
  @Override
  public void onRequestPermissionsResult(
      int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
    switch (requestCode) {
      case PERMISSIONS_REQUEST_FINE_LOCATION:
        // TODO: check if the permission was granted, and do something when it was not
        locationListener.connectGoogleApi();
        break;

      default:
        // Some other permission was granted
    }
  }
示例#4
0
  /** Request permissions at runtime (required for Android 6.0). */
  void requestPermissions() {
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
        != PackageManager.PERMISSION_GRANTED) {

      // if(ActivityCompat.shouldShowRequestPermissionRationale(this,
      // Manifest.permission.READ_CONTACTS)) {
      // TODO: Show an explanation
      // } else {
      ActivityCompat.requestPermissions(
          this,
          new String[] {Manifest.permission.ACCESS_FINE_LOCATION},
          PERMISSIONS_REQUEST_FINE_LOCATION);
      // }
    } else {
      locationListener.connectGoogleApi();
    }
  }