I want to get current location of user by using play service api. But always its calling onConnectionFailed() method. I have added google-services.json file with SHA-1 key. But its showing the Toast message written in onConnectionFailed() method. How can i fix it?
Here is my code -
public class HomeActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
private GoogleApiClient mGoogleApiClient;
private Location mLastLocation;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
//setup GoogleApiClient
setupGoogleApiClient();
}
}
}
//setup GoogleApiClient object
private void setupGoogleApiClient() {
// Create an instance of GoogleAPIClient.
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
mGoogleApiClient.connect();
}
protected void onStart() {
super.onStart();
}
protected void onStop() {
mGoogleApiClient.disconnect();
super.onStop();
}
#Override
public void onConnected(#Nullable Bundle bundle) {
Toast.makeText(this, "Connected with google play service", Toast.LENGTH_LONG).show();
}
#Override
public void onConnectionSuspended(int i) {
Toast.makeText(this, "Connection suspended with google play service", Toast.LENGTH_LONG).show();
}
#Override
public void onConnectionFailed(#NonNull ConnectionResult connectionResult) {
Toast.makeText(this, "Failed to connect with google play service", Toast.LENGTH_LONG).show();
}
}
Try changing play service version in your gradle file,
if you are using
compile 'com.google.android.gms:play-services:10.0.1'
try with
compile 'com.google.android.gms:play-services:8.x.x'
and other combination.
Note:- replace "x" with suitable values
Related
I want to detect screenshots inside a specific activity inside my app. I decided to use this ScreenShot Detector library but unfortunately this does not detect any screenshots for some reason.
I added some code to my activity to check if all the required permissions are grandent and it still doesn't work.
My Activity:
public class UserProfileActivity extends AppCompatActivity implements ScreenshotDetectionDelegate.ScreenshotDetectionListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_profile);
ActivityResultLauncher<String> requestPermissionLauncher =
registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {
if (isGranted) {
Toast.makeText(this, "Permission ok", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Permission req", Toast.LENGTH_SHORT).show();
// Explain to the user that the feature is unavailable because the
// features requires a permission that the user has denied. At the
// same time, respect the user's decision. Don't link to system
// settings in an effort to convince the user to change their
// decision.
}
});
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
// You can use the API that requires the permission.
requestPermissionLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE);
}
#Override
public void onBackPressed() {
super.onBackPressed();
finish();
CustomIntent.customType(UserProfileActivity.this, "right-to-left");
}
#Override
protected void onStart() {
super.onStart();
screenshotDetectionDelegate.startScreenshotDetection();
}
#Override
protected void onStop() {
super.onStop();
screenshotDetectionDelegate.stopScreenshotDetection();
}
#Override
protected void onResume() {
super.onResume();
screenshotDetectionDelegate.startScreenshotDetection();
}
#Override
public void onScreenCaptured(#NonNull String s) {
sendNotificationToUser("screenshot");
Toast.makeText(UserProfileActivity.this, "Profile Screenshotted", Toast.LENGTH_SHORT).show();
}
#Override
public void onScreenCapturedWithDeniedPermission() {
Toast.makeText(this, "Permission denied", Toast.LENGTH_SHORT).show();
}
}
I am calling a service which connects to googleapiclient. Whenever the service is called first time, everything works smooth, client is connected, Onconnected is called. But the moment I recall service without stopping, I get googleapiclient connected but Onconnected is never called. Why So? Is there required to terminate service everytime. Here is the code:
public class ALW extends Service implements GoogleApiClient.OnConnectionFailedListener, GoogleApiClient.ConnectionCallbacks, LocationListener {
private GoogleApiClient mGoogleApiClient;
#Override
public void onDestroy() {
super.onDestroy();
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
Log.d("ALWFA", "Stopped");
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("ALWFA", "Called");
if (!mGoogleApiClient.isConnected()) {
Log.e("ALWFA", "Called for Connection");
mGoogleApiClient.connect();
} else {
Log.e("ALWFA", "Already Connected");
}
//Do Work
return super.onStartCommand(intent, flags, startId);
}
#Nullable
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onCreate() {
super.onCreate();
buildGoogleApiClient();
}
#Override
public void onConnected(#Nullable Bundle bundle) {
Log.d("Google Client", "Connected");
//Do work
}
#Override
public void onConnectionSuspended(int i) {
System.out.println("Connection Sus");
buildGoogleApiClient();
}
#Override
public void onConnectionFailed(#NonNull ConnectionResult connectionResult) {
Log.i("Connection Error", "onConnectionFailed:" + connectionResult.getErrorCode() + "," + connectionResult.getErrorMessage());
buildGoogleApiClient();
System.out.println("Connection Failed");
}
synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
}
and I m not getting any error in Onconenctiofailed. Normally code stuck at onStartCommand: "ALWFA Called". whenever service is called second time.
You should check before calling it again like this
if(mGoogleApiClient!=null && !mGoogleApiClient.isConnected())
{
//Do your work
}
and implement these methods
#Override
protected void onStart() {
super.onStart();
if (mGoogleApiClient != null)
mGoogleApiClient.connect();
}
#Override
protected void onStop() {
super.onStop();
if (mGoogleApiClient != null)
mGoogleApiClient.disconnect();
}
I'm trying to build an app that will show me my location in googleMap and will update my location every few seconds.
here is my code:
public class MapsActivity extends FragmentActivity implements
ConnectionCallbacks, OnConnectionFailedListener, LocationListener, OnMapReadyCallback {
protected static final String TAG = "location-updates-sample";
/**
* The desired interval for location updates. Inexact. Updates may be more or less frequent.
*/
public static final long UPDATE_INTERVAL_IN_MILLISECONDS = 10000;
/**
* The fastest rate for active location updates. Exact. Updates will never be more frequent
* than this value.
*/
public static final long FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS =
UPDATE_INTERVAL_IN_MILLISECONDS / 2;
// Keys for storing activity state in the Bundle.
protected final static String REQUESTING_LOCATION_UPDATES_KEY = "requesting-location-updates-key";
protected final static String LOCATION_KEY = "location-key";
protected GoogleApiClient mGoogleApiClient;
protected LocationRequest mLocationRequest;
protected Location mCurrentLocation;
/**
* Tracks the status of the location updates request. Value changes when the user presses the
* Start Updates and Stop Updates buttons.
*/
protected Boolean mRequestingLocationUpdates;
private GoogleMap mMap;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
mRequestingLocationUpdates = false;
updateValuesFromBundle(savedInstanceState);
buildGoogleApiClient();
}
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng loc = new LatLng(-34,151);
mMap.addMarker(new MarkerOptions().position(loc).title("my location"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(loc));
startUpdates();
}
private void updateValuesFromBundle(Bundle savedInstanceState) {
Log.i(TAG, "Updating values from bundle");
if (savedInstanceState != null) {
if (savedInstanceState.keySet().contains(REQUESTING_LOCATION_UPDATES_KEY)) {
mRequestingLocationUpdates = savedInstanceState.getBoolean(
REQUESTING_LOCATION_UPDATES_KEY);
}
// Update the value of mCurrentLocation from the Bundle and update the UI to show the
// correct latitude and longitude.
if (savedInstanceState.keySet().contains(LOCATION_KEY)) {
// Since LOCATION_KEY was found in the Bundle, we can be sure that mCurrentLocation
// is not null.
mCurrentLocation = savedInstanceState.getParcelable(LOCATION_KEY);
}
updateUI();
}
}
protected synchronized void buildGoogleApiClient() {
Log.i(TAG, "Building GoogleApiClient");
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
createLocationRequest();
}
protected void createLocationRequest() {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
public void startUpdates() { // start updating location
if (!mRequestingLocationUpdates) {
mRequestingLocationUpdates = true;
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
}
}
public void stopUpdates() { // stop updating location
if (mRequestingLocationUpdates) {
mRequestingLocationUpdates = false;
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
}
}
/**
* Updates the latitude, the longitude, and the last location time in the UI.
*/
private void updateUI() {
LatLng loc = new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude());
mMap.addMarker(new MarkerOptions().position(loc).title("my location"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(loc));
}
#Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
#Override
public void onResume() {
super.onResume();
if (mGoogleApiClient.isConnected() && mRequestingLocationUpdates) {
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
}
}
#Override
protected void onPause() {
super.onPause();
// Stop location updates to save battery, but don't disconnect the GoogleApiClient object.
if (mGoogleApiClient.isConnected()) {
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
}
}
#Override
protected void onStop() {
mGoogleApiClient.disconnect();
super.onStop();
}
/**
* Runs when a GoogleApiClient object successfully connects.
*/
#Override
public void onConnected(Bundle connectionHint) {
Log.i(TAG, "Connected to GoogleApiClient");
if (mCurrentLocation == null) {
mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
updateUI();
}
if (mRequestingLocationUpdates) {
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
}
}
#Override
public void onLocationChanged(Location location) {
mCurrentLocation = location;
updateUI();
Toast.makeText(this, getResources().getString(R.string.location_updated_message),
Toast.LENGTH_SHORT).show();
}
#Override
public void onConnectionSuspended(int cause) {
// The connection to Google Play services was lost for some reason. We call connect() to
// attempt to re-establish the connection.
Log.i(TAG, "Connection suspended");
mGoogleApiClient.connect();
}
#Override
public void onConnectionFailed(ConnectionResult result) {
// Refer to the javadoc for ConnectionResult to see what error codes might be returned in
// onConnectionFailed.
Log.i(TAG, "Connection failed: ConnectionResult.getErrorCode() = " + result.getErrorCode());
}
/**
* Stores activity data in the Bundle.
*/
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putBoolean(REQUESTING_LOCATION_UPDATES_KEY, mRequestingLocationUpdates);
savedInstanceState.putParcelable(LOCATION_KEY, mCurrentLocation);
super.onSaveInstanceState(savedInstanceState);
}
}
This code is a part from a sample code from google but i've changed a few things and added the googleMap, its just crashing after onMapReady().
stacktrace:
java.lang.IllegalStateException: GoogleApiClient is not connected yet.
at com.google.android.gms.common.api.internal.zzh.zzb(Unknown Source)
at com.google.android.gms.common.api.internal.zzl.zzb(Unknown Source)
at com.google.android.gms.common.api.internal.zzj.zzb(Unknown Source)
at com.google.android.gms.location.internal.zzd.requestLocationUpdates(Unknown Source)
at com.idanofek.photomap.MapsActivity.startUpdates(MapsActivity.java:135)
at com.idanofek.photomap.MapsActivity.onMapReady(MapsActivity.java:91)
at com.google.android.gms.maps.SupportMapFragment$zza$1.zza(Unknown Source)
at com.google.android.gms.maps.internal.zzo$zza.onTransact(Unknown Source)
at android.os.Binder.transact(Binder.java:387)
at com.google.android.gms.maps.internal.be.a(SourceFile:82)
at com.google.maps.api.android.lib6.e.fb.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Before any operation is executed, the GoogleApiClient must be connect using the 'connect()' method. The client is not considered connected until the onConnected(Bundle) callback has been called.
You should instantiate a client object in your Activity's 'onCreated(Bundle)' method then call connect() on onStart()
You may call startLocationUpdate() from the onConnected() callback
#Override
public void onConnected(Bundle connectionHint) {
...
if (mRequestingLocationUpdates) {
startLocationUpdates();
}
}
protected void startLocationUpdates() {
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
}
Here's a Google Documentation regarding Location Updates: http://developer.android.com/training/location/receive-location-updates.html
I have an app that needs the location of the user, and I am new in implementing location service of Google.
I made a separate java class to handle things related to getting location, and then using the location information in a activity just to show the location(so far), but I get the default value of 0 for latitude and longitude in my activity.
Here's the java class implementing the location related stuff, following google guideline:
import android.content.Context;
import android.location.Location;
import android.os.Bundle;
import android.util.Log;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationServices;
public class CommentLocation implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
private double mLatitude;
private double mLongitude;
private GoogleApiClient mGoogleApiClient;
private Location mLastLocation;
public CommentLocation(Context context){
buildGoogleApiClient(context);
}
public double getCommentLongitude() {
return mLongitude;
}
public double getCommentLatitude() {
return mLatitude;
}
protected synchronized void buildGoogleApiClient(Context context) {
mGoogleApiClient = new GoogleApiClient.Builder(context)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
#Override
public void onConnected(Bundle connectionHint) {
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if (mLastLocation != null) {
mLatitude = mLastLocation.getLatitude();
mLongitude = mLastLocation.getLongitude();
}
else{
Log.v(CommentLocation.class.getName(), "LOCATION WAS NOT RECEIVED");
}
Log.v(CommentLocation.class.getName(), "CONNECTION TO GET LOCATION IS SUCCESSFUL");
}
#Override
public void onConnectionSuspended(int i) {
//TODO
Log.v(CommentLocation.class.getName(), "CONNECTION TO GET LOCATION IS SUSPENDED");
}
#Override
public void onConnectionFailed(ConnectionResult connectionResult) {
//TODO
Log.v(CommentLocation.class.getName(), "CONNECTION TO GET LOCATION IS FAILED");
}
}
And here is the caller of this location class (the fragment PostCommentFragment)
public class PostCommentFragment extends Fragment {
private TextView mLatitudeText;
private TextView mLongtitudeText;
private CommentDatabase database;
private CommentLocation location;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
database = new CommentDatabase(getActivity());
location = new CommentLocation(getActivity());
setHasOptionsMenu(true);
}
#TargetApi(11) //for setDisplayHomeAsUpEnabled function
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_post_comment, container, false);
//to enable the app icon to work as a button and get the caret to appear in fragment's view
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
if(NavUtils.getParentActivityName(getActivity()) != null) {
getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
mLatitudeText = (TextView) v.findViewById(R.id.latitude_text);
mLongtitudeText = (TextView) v.findViewById(R.id.longitude_text);
mLatitudeText.setText(String.valueOf(location.getCommentLatitude()));
mLongtitudeText.setText(String.valueOf(location.getCommentLongitude()));
return v;
}
What am I doing wrong here?
I also added this line compile 'com.google.android.gms:play-services:7.8.0'
to build.gradle(Module:app)->under dependencies, and asked for permission in Manifest. Thanks!
Issue 1:
You're not calling connect() on mGoogleApiClient.
You need to call connect in order for onConnected() to be invoked:
public CommentLocation(Context context){
buildGoogleApiClient(context);
mGoogleApiClient.connect(); //added
}
Issue 2:
It looks like you're only using getLastLocation(). This may work for your needs, but if you need a location, this method is not guaranteed to give one. The getLastLocation() method can and will return null. The main problem is that it doesn't prompt a request to the OS for a new location lock, instead it just checks if there was a last known location from some other app's location request. If no other app had recently made a location request, then you get a null location returned to you.
The only way to guarantee that you actually get a location is to request one, and this is done with a call to requestLocationUpdates().
Issue 3:
Given that it takes time to connect to the Google Api Client, the timing may be off, and even if you get a location from getLastLocation(), you may have already requested it from your Fragment.
To get around this issue, you could use a BroadcastReceiver to send the location from the CommentLocation class to the Fragment.
Note that in general keeping the location functionality encapsulated is a better approach, but it's more work to implement. You might want to go with a more simple design, where the location functionality is within the Activity that is associated with this Fragment. Then you could just call into the Fragment when a location is available.
Sample Activity code with a location listener:
public class MainActivity extends Activity implements
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener {
LocationRequest mLocationRequest;
GoogleApiClient mGoogleApiClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buildGoogleApiClient();
mGoogleApiClient.connect();
}
#Override
protected void onPause(){
super.onPause();
if (mGoogleApiClient != null) {
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
}
}
protected synchronized void buildGoogleApiClient() {
Toast.makeText(this,"buildGoogleApiClient",Toast.LENGTH_SHORT).show();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
#Override
public void onConnected(Bundle bundle) {
Toast.makeText(this,"onConnected",Toast.LENGTH_SHORT).show();
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(10);
mLocationRequest.setFastestInterval(10);
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
//mLocationRequest.setPriority(LocationRequest.PRIORITY_LOW_POWER);
//mLocationRequest.setSmallestDisplacement(0.1F);
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}
#Override
public void onConnectionSuspended(int i) {
Toast.makeText(this,"onConnectionSuspended",Toast.LENGTH_SHORT).show();
}
#Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Toast.makeText(this,"onConnectionFailed",Toast.LENGTH_SHORT).show();
}
#Override
public void onLocationChanged(Location location) {
Log.d("locationtesting", "accuracy: " + location.getAccuracy() + " lat: " + location.getLatitude() + " lon: " + location.getLongitude());
Toast.makeText(this,"Location Changed",Toast.LENGTH_SHORT).show();
}
}
I'm trying to connect mGoogleAPIClient, following this Guide.
When i debug, a little window popsup asking me what googleplus account i would like to sign in as. As soon as I select my main account and click OK, it stops from there and does absolutely nothing. No error Messages, Warnings, Infos, no nothing.
My Source:
public class MainMenu_Activity extends Activity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
private Button btnStart;
private Button btnSubmit;
private Button btnHOF;
private GoogleApiClient mGoogleApiClient;
public static int REQUEST_LEADERBOARD = 100;
// Request code to use when launching the resolution activity
private static final int REQUEST_RESOLVE_ERROR = 1001;
// Bool to track whether the app is already resolving an error
private boolean mResolvingError = false;
private static final String STATE_RESOLVING_ERROR = "resolving_error";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mainmenu);
mResolvingError = savedInstanceState != null
&& savedInstanceState.getBoolean(STATE_RESOLVING_ERROR, false);
this.mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.addScope(Plus.SCOPE_PLUS_PROFILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
#Override
protected void onStart() {
super.onStart();
if (!mResolvingError) { // more about this later
mGoogleApiClient.connect();
}
}
#Override
protected void onStop() {
mGoogleApiClient.disconnect();
super.onStop();
}
#Override
public void onConnected(Bundle connectionHint) {
// Connected to Google Play services!
// The good stuff goes here.
System.out.println("CONNECTED!");
}
#Override
public void onConnectionSuspended(int cause) {
// The connection has been interrupted.
// Disable any UI components that depend on Google APIs
// until onConnected() is called.
System.out.println("SUSPENDED!");
}
#Override
public void onConnectionFailed(ConnectionResult result) {
System.out.println("Connection Failed - mResolvingError=" + mResolvingError);
if (mResolvingError) {
System.out.println("Connection Failed - Already attempting to resolve...");
// Already attempting to resolve an error.
return;
} else if (result.hasResolution()) {
System.out.println("Connection Failed - resolving now...");
try {
mResolvingError = true;
result.startResolutionForResult(this, REQUEST_RESOLVE_ERROR);
} catch (IntentSender.SendIntentException e) {
System.out.println("Connection Failed - Exception...");
// There was an error with the resolution intent. Try again.
mGoogleApiClient.connect();
}
} else {
// Show dialog using GooglePlayServicesUtil.getErrorDialog()
Dialog errDia = GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this, 1);
errDia.show();
mResolvingError = true;
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_RESOLVE_ERROR) {
mResolvingError = false;
if (resultCode == RESULT_OK) {
// Make sure the app is not already connected or attempting to connect
if (!mGoogleApiClient.isConnecting() &&
!mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
}
}
}
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(STATE_RESOLVING_ERROR, mResolvingError);
}
}
As you can see, i tagged certain places to follow the procedure.
Well this is what the logcat logs:
06-02 17:52:48.175 2302-2302/com.dudewithfacial.game.gamebase I/System.out﹕
Connection Failed - mResolvingError=false 06-02 17:52:48.175
2302-2302/com.dudewithfacial.game.gamebase I/System.out﹕ Connection Failed -
resolving now...
I follow the guide step by step :(
Well appaently not really, what am i doing wrong Stackoverflow-Gurus?
Thx boys, really appreciated!
NVM, figured out i can't use Launchmode, SingleUser, SingleInstance.
Also haven't configred some of the requested APIs such as ".addApi(Plus.API)"
Problem fixed.