title: mFusedLocationClient.getLastLocation() doesn't return anything
body: <p>i'm trying to create a simple app to show gps location and i always get an exception returned 
  this exception </p>
  
  <pre><code>Log.w(TAG, "getLastLocation:exception", task.getException());showSnackbar(getString(R.string.no_location_detected));
  </code></pre>
  
  <p>it seems as there's no last location registered but i know for sure there's
  i tried using googleservice api with no luck as well
  my layout is simple only a text view and an input view with no function yet so it can be ignored for the purposes of this question</p>
  
  <p>my java activity </p>
  
  <pre><code>/**
    * An example full-screen activity that shows and hides the system UI (i.e.
   * status bar and navigation/system bar) with user interaction.
  */
  public class FullscreenActivity extends AppCompatActivity {
  /**
   * Whether or not the system UI should be auto-hidden after
   * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
   */
  private static final boolean AUTO_HIDE = true;
  private static final String TAG = FullscreenActivity.class.getSimpleName();
  
  private static final int REQUEST_PERMISSIONS_REQUEST_CODE = 34;
  
  /**
   * Provides the entry point to the Fused Location Provider API.
   */
  private FusedLocationProviderClient mFusedLocationClient;
  
  /**
   * Represents a geographical location.
   */
  protected Location mLastLocation;
  
  private String mLatitudeLabel;
  private String mLongitudeLabel;
  private TextView mLatitudeText;
  private TextView mLongitudeText;
  private String provider;
  /**
   * If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
   * user interaction before hiding the system UI.
   */
  private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
  
  /**
   * Some older devices needs a small delay between UI widget updates
   * and a change of the status and navigation bar.
   */
  private static final int UI_ANIMATION_DELAY = 300;
  private final Handler mHideHandler = new Handler();
  private View mContentView;
  private final Runnable mHidePart2Runnable = new Runnable() {
      @SuppressLint("InlinedApi")
      @Override
      public void run() {
          // Delayed removal of status and navigation bar
  
          // Note that some of these constants are new as of API 16 (Jelly Bean)
          // and API 19 (KitKat). It is safe to use them, as they are inlined
          // at compile-time and do nothing on earlier devices.
          mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
                  | View.SYSTEM_UI_FLAG_FULLSCREEN
                  | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                  | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                  | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                  | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
      }
  };
  private View mControlsView;
  private final Runnable mShowPart2Runnable = new Runnable() {
      @Override
      public void run() {
          // Delayed display of UI elements
          ActionBar actionBar = getSupportActionBar();
          if (actionBar != null) {
              actionBar.show();
          }
          mControlsView.setVisibility(View.VISIBLE);
      }
  };
  private boolean mVisible;
  private final Runnable mHideRunnable = new Runnable() {
      @Override
      public void run() {
          hide();
      }
  };
  /**
   * Touch listener to use for in-layout UI controls to delay hiding the
   * system UI. This is to prevent the jarring behavior of controls going away
   * while interacting with activity UI.
   */
  private final View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
      @Override
      public boolean onTouch(View view, MotionEvent motionEvent) {
          if (AUTO_HIDE) {
              delayedHide(AUTO_HIDE_DELAY_MILLIS);
          }
          return false;
      }
  };
  
  /**
   * ATTENTION: This was auto-generated to implement the App Indexing API.
   * See https://g.co/AppIndexing/AndroidStudio for more information.
   */
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      this.requestWindowFeature(Window.FEATURE_NO_TITLE);
      setContentView(R.layout.activity_fullscreen);
  
      mVisible = true;
      mControlsView = findViewById(R.id.fullscreen_content_controls);
      mContentView = findViewById(R.id.fullscreen_content);
  
      mLatitudeLabel = getResources().getString(R.string.latitude_label);
      mLongitudeLabel = getResources().getString(R.string.longitude_label);
      mLatitudeText = (TextView) findViewById((R.id.latitude_text));
      mLongitudeText = (TextView) findViewById((R.id.longitude_text));
  
      mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
      // Set up the user interaction to manually show or hide the system UI.
      mContentView.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              toggle();
          }
      });
  
      // Upon interacting with UI controls, delay any scheduled hide()
      // operations to prevent the jarring behavior of controls going away
      // while interacting with the UI.
      findViewById(R.id.dummy_button).setOnTouchListener(mDelayHideTouchListener);
      // ATTENTION: This was auto-generated to implement the App Indexing API.
      // See https://g.co/AppIndexing/AndroidStudio for more information.
  
      final Button button = (Button) findViewById(R.id.button);
      button.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v) {
              // Code here executes on main thread after user presses button
              // get EditText by id and store it into "inputTxt"
              EditText inputTxt = (EditText) findViewById(R.id.input);
              onStart();
              // Store EditText - Input in variable
  
              String typedText = inputTxt.getText().toString();
              Log.v(typedText, "index");
          }
      });
  
  
  
  
  }
  
  
  @Override
  public void onStart() {
      super.onStart();
  
  
      if (!checkPermissions()) {
          requestPermissions();
      } else {
          getLastLocation();
      }
  }
  
  /**
   * Provides a simple way of getting a device's location and is well suited for
   * applications that do not require a fine-grained location and that do not need location
   * updates. Gets the best and most recent location currently available, which may be null
   * in rare cases when a location is not available.
   * &lt;p&gt;
   * Note: this method should be called after location permission has been granted.
   */
  
  @SuppressWarnings("MissingPermission")
  private void getLastLocation() {
      mFusedLocationClient.getLastLocation()
              .addOnCompleteListener(this, new OnCompleteListener&lt;Location&gt;() {
                  @Override
                  public void onComplete(@NonNull Task&lt;Location&gt; task) {
                      if (task.isSuccessful() &amp;&amp; task.getResult() != null) {
                          mLastLocation = task.getResult();
  
                          mLatitudeText.setText(String.format(Locale.ENGLISH, "%s: %f",
                                  mLatitudeLabel,
                                  mLastLocation.getLatitude()));
                          mLongitudeText.setText(String.format(Locale.ENGLISH, "%s: %f",
                                  mLongitudeLabel,
                                  mLastLocation.getLongitude()));
                          Log.v(String.format(Locale.ENGLISH, "%s: %f",
                                  mLatitudeLabel,
                                  mLastLocation.getLatitude()),"location");
                      } else {
  
                          Log.w(TAG, "getLastLocation:exception", task.getException());
                          showSnackbar(getString(R.string.no_location_detected));
                      }
                  }
              });
  }
  
  /**
   * Shows a {@link Snackbar} using {@code text}.
   *
   * @param text The Snackbar text.
   */
  private void showSnackbar(final String text) {
      View container = findViewById(R.id.fullscreen_content);
      if (container != null) {
          Snackbar.make(container, text, Snackbar.LENGTH_LONG).show();
      }
  }
  
  /**
   * Shows a {@link Snackbar}.
   *
   * @param mainTextStringId The id for the string resource for the Snackbar text.
   * @param actionStringId   The text of the action item.
   * @param listener         The listener associated with the Snackbar action.
   */
  private void showSnackbar(final int mainTextStringId, final int actionStringId,
                            View.OnClickListener listener) {
      Snackbar.make(findViewById(android.R.id.content),
              getString(mainTextStringId),
              Snackbar.LENGTH_INDEFINITE)
              .setAction(getString(actionStringId), listener).show();
  }
  
  /**
   * Return the current state of the permissions needed.
   */
  private boolean checkPermissions() {
      int permissionState = ActivityCompat.checkSelfPermission(this,
              Manifest.permission.ACCESS_COARSE_LOCATION);
      return permissionState == PackageManager.PERMISSION_GRANTED;
  }
  
  private void startLocationPermissionRequest() {
      ActivityCompat.requestPermissions(FullscreenActivity.this,
              new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
              REQUEST_PERMISSIONS_REQUEST_CODE);
  }
  
  private void requestPermissions() {
      boolean shouldProvideRationale =
              ActivityCompat.shouldShowRequestPermissionRationale(this,
                      Manifest.permission.ACCESS_COARSE_LOCATION);
  
      // Provide an additional rationale to the user. This would happen if the user denied the
      // request previously, but didn't check the "Don't ask again" checkbox.
      if (shouldProvideRationale) {
          Log.i(TAG, "Displaying permission rationale to provide additional context.");
  
          showSnackbar(R.string.permission_rationale, android.R.string.ok,
                  new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          // Request permission
                          startLocationPermissionRequest();
                      }
                  });
  
      } else {
          Log.i(TAG, "Requesting permission");
          // Request permission. It's possible this can be auto answered if device policy
          // sets the permission in a given state or the user denied the permission
          // previously and checked "Never ask again".
          startLocationPermissionRequest();
      }
  }
  
  /**
   * Callback received when a permissions request has been completed.
   */
  @Override
  public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                                         @NonNull int[] grantResults) {
      Log.i(TAG, "onRequestPermissionResult");
      if (requestCode == REQUEST_PERMISSIONS_REQUEST_CODE) {
          if (grantResults.length &lt;= 0) {
              // If user interaction was interrupted, the permission request is cancelled and you
              // receive empty arrays.
              Log.i(TAG, "User interaction was cancelled.");
          } else if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
              // Permission granted.
              getLastLocation();
          } else {
              // Permission denied.
  
              // Notify the user via a SnackBar that they have rejected a core permission for the
              // app, which makes the Activity useless. In a real app, core permissions would
              // typically be best requested during a welcome-screen flow.
  
              // Additionally, it is important to remember that a permission might have been
              // rejected without asking the user for permission (device policy or "Never ask
              // again" prompts). Therefore, a user interface affordance is typically implemented
              // when permissions are denied. Otherwise, your app could appear unresponsive to
              // touches or interactions which have required permissions.
              showSnackbar(R.string.permission_denied_explanation, R.string.settings,
                      new View.OnClickListener() {
                          @Override
                          public void onClick(View view) {
                              // Build intent that displays the App settings screen.
                              Intent intent = new Intent();
                              intent.setAction(
                                      Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                              Uri uri = Uri.fromParts("package",
                                      BuildConfig.APPLICATION_ID, null);
                              intent.setData(uri);
                              intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                              startActivity(intent);
                          }
                      });
          }
      }
  }
  
  
  
  
  
  
  
  
  @Override
  protected void onPostCreate(Bundle savedInstanceState) {
      super.onPostCreate(savedInstanceState);
  
      // Trigger the initial hide() shortly after the activity has been
      // created, to briefly hint to the user that UI controls
      // are available.
      delayedHide(100);
  }
  
  private void toggle() {
  
      hide();
  
  }
  
  private void hide() {
      // Hide UI first
      ActionBar actionBar = getSupportActionBar();
  
      actionBar.hide();
  
      mControlsView.setVisibility(View.GONE);
      mVisible = false;
  
      // Schedule a runnable to remove the status and navigation bar after a delay
      mHideHandler.removeCallbacks(mShowPart2Runnable);
      mHideHandler.postDelayed(mHidePart2Runnable, UI_ANIMATION_DELAY);
  }
  
  @SuppressLint("InlinedApi")
  private void show() {
      // Show the system bar
      mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
              | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
      mVisible = true;
  
      // Schedule a runnable to display UI elements after a delay
      mHideHandler.removeCallbacks(mHidePart2Runnable);
      mHideHandler.postDelayed(mShowPart2Runnable, UI_ANIMATION_DELAY);
  }
  
  /**
   * Schedules a call to hide() in [delay] milliseconds, canceling any
   * previously scheduled calls.
   */
  private void delayedHide(int delayMillis) {
      mHideHandler.removeCallbacks(mHideRunnable);
      mHideHandler.postDelayed(mHideRunnable, delayMillis);
  }
  
  /**
   * ATTENTION: This was auto-generated to implement the App Indexing API.
   * See https://g.co/AppIndexing/AndroidStudio for more information.
   */
  </code></pre>
  
  <p>}</p>