google api client callback is never called - android

I am trying to get the last known location using google services API, but after I build the GoogleApiClient, no callback method is ever fired.
My activity looks like that :
public class MainActivity extends Activity implements FragmentObserver, SessionSpotListObserver,
ConnectionCallbacks, OnConnectionFailedListener{
//Objects used for the location API
private Location mLastLocation;
private GoogleApiClient mGoogleApiClient;
// Request code to use when launching the resolution activity
private static final int REQUEST_RESOLVE_ERROR = 1001;
// Unique tag for the error dialog fragment
private static final String DIALOG_ERROR = "dialog_error";
// Bool to track whether the app is already resolving an error
private boolean mResolvingError = false;
public static final String STATE_RESOLVING_ERROR = "resolving_state";
//Request code to use when launching the activity to fix the connection to google API
private static final int REQUEST_SOLVE_CONNEXION = 999;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//We make sure that google play service is available on the device
if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS){
//We get a connection to the Google Play Service API to get the location of the user
buildGoogleApiClient();
}
else {
GooglePlayServicesUtil.getErrorDialog(GooglePlayServicesUtil.isGooglePlayServicesAvailable(this),
this,
REQUEST_SOLVE_CONNEXION);
}
}
#Override
public void onConnectionFailed(ConnectionResult result) {
if (mResolvingError) {
// Already attempting to resolve an error.
return;
} else if (result.hasResolution()) {
try {
mResolvingError = true;
result.startResolutionForResult(this, REQUEST_RESOLVE_ERROR);
} catch (SendIntentException e) {
// There was an error with the resolution intent. Try again.
mGoogleApiClient.connect();
}
} else {
// Show dialog using GooglePlayServicesUtil.getErrorDialog()
showErrorDialog(result.getErrorCode());
mResolvingError = true;
}
}
// The rest of this code is all about building the error dialog
/* Creates a dialog for an error message */
private void showErrorDialog(int errorCode) {
// Create a fragment for the error dialog
ErrorDialogFragment dialogFragment = new ErrorDialogFragment();
// Pass the error that should be displayed
Bundle args = new Bundle();
args.putInt(DIALOG_ERROR, errorCode);
dialogFragment.setArguments(args);
dialogFragment.show(getFragmentManager(), "errordialog");
}
/* Called from ErrorDialogFragment when the dialog is dismissed. */
public void onDialogDismissed() {
mResolvingError = false;
}
/* A fragment to display an error dialog */
public static class ErrorDialogFragment extends DialogFragment {
public ErrorDialogFragment() { }
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Get the error code and retrieve the appropriate dialog
int errorCode = this.getArguments().getInt(DIALOG_ERROR);
return GooglePlayServicesUtil.getErrorDialog(errorCode,
this.getActivity(), REQUEST_RESOLVE_ERROR);
}
#Override
public void onDismiss(DialogInterface dialog) {
((MainActivity)getActivity()).onDialogDismissed();
}
}
#Override
public void onConnected(Bundle arg0) {
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
mGoogleApiClient);
Log.d("API Connection", "The API has connected and the last location is :" + mLastLocation);
if (mLastLocation != null) {
}
}
#Override
public void onConnectionSuspended(int arg0) {
// TODO Auto-generated method stub
}
/**
* Creates the connexion to the Google API. Once the API is connected, the
* onConnected method is called.
*/
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
I placed breakpoints on all callback methods, that is how I know that none is called.
Because at this stage I am not using Google Map Api, I did not register my app to get a key. Do I need to do that even if I just get the location ?
Don't hesitate to tell me if you need more info.
Thank you all.

You never call mGoogleApiClient.connect() after building your GoogleApiClient. Your onCreate() should instead be:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
buildGoogleApiClient();
mGoogleApiClient.connect();
}
Note that there is no need to call GooglePlayServicesUtil.isGooglePlayServicesAvailable() if you are using GoogleApiClient as connect() includes that check as well.

consider calling onLocationChanged() and passing it's Location parameter to mLastLocation for continuous location update when the user location changes. Also you might want to reduce the drain on your battery by setting LocationRequest() interval and distance to a small value.

Related

GoogleApiClient in Fragment Android

I try to learn Android by myself. And in my app, I want to use fragment to show google map and when user open my app, I want to get current location by using GoogleApiClient
My fragment code:
public class HomeFragment extends Fragment implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
public interface comuticateParent {
public void sendMess(String text);
}
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
public HomeFragment() {
// Required empty public constructor
}
public static HomeFragment newInstance(String param1, String param2) {
HomeFragment fragment = new HomeFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
comuticateParent callback;
Button btn1;
TextView textView;
MapView mMapView;
GoogleApiClient mGoogleApiClient;
Location mLastLocation;
LocationRequest mLocationRequest;
private GoogleMap googleMap;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
mMapView = (MapView) rootView.findViewById(R.id.mapView);
mMapView.onCreate(savedInstanceState);
mMapView.onResume(); // needed to get the map to display immediately
try {
MapsInitializer.initialize(getActivity().getApplicationContext());
} catch (Exception e) {
e.printStackTrace();
}
mMapView.getMapAsync(new OnMapReadyCallback() {
#Override
public void onMapReady(GoogleMap mMap) {
googleMap = mMap;
googleMap.setMyLocationEnabled(true);
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
Log.d("onCreateView", Boolean.toString(mGoogleApiClient.isConnected()));
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mylocation, 13));
}
});
return rootView;
}
#Override
public void onStart() {
mGoogleApiClient.connect();
Log.d("ConnectonStart", "Connected ");
Log.d("ONstart", Boolean.toString(mGoogleApiClient.isConnected()));
super.onStart();
}
#Override
public void onStop() {
mGoogleApiClient.disconnect();
super.onStop();
}
#Override
public void onResume() {
mGoogleApiClient.connect();
super.onResume();
mMapView.onResume();
}
#Override
public void onPause() {
super.onPause();
mMapView.onPause();
}
#Override
public void onDestroy() {
super.onDestroy();
mMapView.onDestroy();
}
#Override
public void onLowMemory() {
super.onLowMemory();
mMapView.onLowMemory();
}
#Override
public void onConnected(Bundle bundle) {
Log.d("Connect", "Connected ");
Log.d("onConnected", Boolean.toString(mGoogleApiClient.isConnected()));
}
#Override
public void onConnectionSuspended(int i) {
}
#Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.d("Connect", "failed ");
}
#Override
public void onAttach(Context context) {
super.onAttach(context);
Activity activity;
if (context instanceof Activity) {
activity = (Activity) context;
callback = (comuticateParent) getActivity();
}
}
}
And problem here:
-Log in method onCreateView appears before log in method onconnected, so I can't get getLastLocation() because The googleAPIClient is not connect yet.
I have search in google but I don't know how to fix it.
Please help me!
Sorry about my best English.
First problem Log in method onCreateView appears before log in method onconnected, because GoogleApiClient will accessing Google APIs, verify app configuration, verify certificate fingerprint, etc. It take too long to process. To avoid blocking the UI thread, it'll execute in another thread and use asynchronous callback.
Second problem I can't get getLastLocation() because The googleAPIClient is not connect yet, because FusedLocationApi will only maintain background, so you need to get GoogleMap in background.
See my sample here: https://gist.github.com/quydm/a458d908c4da2496672f83372304f417
You will have to wait until the GoogleApiClient has connected before you can request location updates. In order to do so, you would move this block of code (currently found in your onCreateView() method):
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
Log.d("onCreateView", Boolean.toString(mGoogleApiClient.isConnected()));
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mylocation, 13));
to the body of the overridden method onConnected().
You cannot have this code directly in onCreateView() because of the very problem you had. The connection must be established first before any location requests are sent. The connection can establish quickly or take longer than normal. It depends on many things outside of your control.
For that reason, I would suggest showing some sort of progress bar to indicate that location services is connecting and then remove the progress bar when onConnected() is called. Of course this depends entirely on your app. If location services is critical for the user to have then this is a must, if not, then you may not need to add it.

GPS tracker with GoogleApiClient

in the last update of google services, Google has depercated LocationClient api and now say use GoogleApiClient.
Now need create the App with GPS report any 30 seconds to my webserver but dont found (or dont understant) how work this new api.
If you have a example using GoogleApiClient please past the link to see or download.
And if have a Service with GoogleApiClient please past the link
Thanks for your help.
If you have installed android sdk then just checkout following directory \extras\google\google_play_services\samples\maps\src\com\example\mapdemo\.
It is having one example of showing current location in GoogleMap and it is using GoogleApiClient to retrieve current location on periodic interval of 5 seconds as described in following code. You can modify it according to your requirements.
MyLocationDemoActivity.java
public class MyLocationDemoActivity extends FragmentActivity
implements
ConnectionCallbacks,
OnConnectionFailedListener,
LocationListener,
OnMyLocationButtonClickListener {
private GoogleMap mMap;
private GoogleApiClient mGoogleApiClient;
private TextView mMessageView;
// These settings are the same as the settings for the map. They will in fact give you updates
// at the maximal rates currently possible.
private static final LocationRequest REQUEST = LocationRequest.create()
.setInterval(5000) // 5 seconds
.setFastestInterval(16) // 16ms = 60fps
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_location_demo);
mMessageView = (TextView) findViewById(R.id.message_text);
}
#Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
setUpGoogleApiClientIfNeeded();
mGoogleApiClient.connect();
}
#Override
public void onPause() {
super.onPause();
if (mGoogleApiClient != null) {
mGoogleApiClient.disconnect();
}
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
mMap.setMyLocationEnabled(true);
mMap.setOnMyLocationButtonClickListener(this);
}
}
}
private void setUpGoogleApiClientIfNeeded() {
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
}
/**
* Button to get current Location. This demonstrates how to get the current Location as required
* without needing to register a LocationListener.
*/
public void showMyLocation(View view) {
if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
String msg = "Location = "
+ LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
}
}
/**
* Implementation of {#link LocationListener}.
*/
#Override
public void onLocationChanged(Location location) {
mMessageView.setText("Location = " + location);
}
/**
* Callback called when connected to GCore. Implementation of {#link ConnectionCallbacks}.
*/
#Override
public void onConnected(Bundle connectionHint) {
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient,
REQUEST,
this); // LocationListener
}
/**
* Callback called when disconnected from GCore. Implementation of {#link ConnectionCallbacks}.
*/
#Override
public void onConnectionSuspended(int cause) {
// Do nothing
}
/**
* Implementation of {#link OnConnectionFailedListener}.
*/
#Override
public void onConnectionFailed(ConnectionResult result) {
// Do nothing
}
#Override
public boolean onMyLocationButtonClick() {
Toast.makeText(this, "MyLocation button clicked", Toast.LENGTH_SHORT).show();
// Return false so that we don't consume the event and the default behavior still occurs
// (the camera animates to the user's current position).
return false;
}
}
I had exactly your same problem. You need to explicitely use GoogleMap.setLocationSource().
Here is an example: Android: Google Maps location with low battery usage

How to handle Internet connectivity lost after onConnected in Google drive android api

I am invoking the google drive api client's connect() method to start a drive communication from my android app. Now for testing purpose, I put in a breakpoint inside the onConnected method and then after the breakpoint was hit, I intentionally turned off the device wifi.
Now, in these cases, it seems, even though the google drive connection was established, and there was a loss of connectivity, the drive api, just leaves that file upload / download request abruptly.
Is there, a good way to handle / notify the user of connectivity loss, while working with drive api in android?
Make sure you are implementing a callback to handle the connection lost. In the documentation page for the API, I could find the following:
public class MyActivity extends FragmentActivity
implements ConnectionCallbacks, OnConnectionFailedListener {
// Request code to use when launching the resolution activity
private static final int REQUEST_RESOLVE_ERROR = 1001;
// Unique tag for the error dialog fragment
private static final String DIALOG_ERROR = "dialog_error";
// Bool to track whether the app is already resolving an error
private boolean mResolvingError = false;
...
#Override
public void onConnectionFailed(ConnectionResult result) {
if (mResolvingError) {
// Already attempting to resolve an error.
return;
} else if (result.hasResolution()) {
try {
mResolvingError = true;
result.startResolutionForResult(this, REQUEST_RESOLVE_ERROR);
} catch (SendIntentException e) {
// There was an error with the resolution intent. Try again.
mGoogleApiClient.connect();
}
} else {
// Show dialog using GooglePlayServicesUtil.getErrorDialog()
showErrorDialog(result.getErrorCode());
mResolvingError = true;
}
}
// The rest of this code is all about building the error dialog
/* Creates a dialog for an error message */
private void showErrorDialog(int errorCode) {
// Create a fragment for the error dialog
ErrorDialogFragment dialogFragment = new ErrorDialogFragment();
// Pass the error that should be displayed
Bundle args = new Bundle();
args.putInt(DIALOG_ERROR, errorCode);
dialogFragment.setArguments(args);
dialogFragment.show(getSupportFragmentManager(), "errordialog");
}
/* Called from ErrorDialogFragment when the dialog is dismissed. */
public void onDialogDismissed() {
mResolvingError = false;
}
/* A fragment to display an error dialog */
public static class ErrorDialogFragment extends DialogFragment {
public ErrorDialogFragment() { }
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Get the error code and retrieve the appropriate dialog
int errorCode = this.getArguments().getInt(DIALOG_ERROR);
return GooglePlayServicesUtil.getErrorDialog(errorCode,
this.getActivity(), REQUEST_RESOLVE_ERROR);
}
#Override
public void onDismiss(DialogInterface dialog) {
((MainActivity)getActivity()).onDialogDismissed();
}
}
}

How to supply location services to diffent activities on Android

I am currently working on an Android app and I am new to the field.
I want to do the following:
Create a class that encapsulates the required features to let an activity know the users location and deliver a map to the activity
This should accomplish the following:
I have a class that connects to the location services to get information and other activities can use this class to get a map (fragment) along with other information (lat long etc) for programmatic use.
I cannot figure it out...I do not want my stuff to an Activity itself
But it seems as if the whole Google Location API of the Play services relies on it being a FragmentActivity (whatever that is)
Any ideas?
PS: I need to maintain support for 2.3.3
UPDATE
I made it to implement a class extending SupportMapFragment (shortened), but I am having trouble with the error handling for the GMS. Works fine on my Galaxy Note 3 but the emulator has an older version of GMS which (due to currently crappy errorhandling) eventually leads to a NullPointer Exception:
public class LocationFragment extends SupportMapFragment implements GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener,
LocationListener {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
view = inflater.inflate(R.layout.map_fragment, container, false);
initilizeMap();
configureLocationClient();
locationManager = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
// Start with updates turned off
updatesRequested = false;
map.getUiSettings().setMyLocationButtonEnabled(true);
locationClient = new LocationClient(activity.getBaseContext(), this, this);
return view;
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activity = getActivity();
checkGooglePlayServices();
}
private boolean checkGooglePlayServices() {
// Check that Google Play services is available
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity.getBaseContext());
// If Google Play services is available
if (ConnectionResult.SUCCESS == resultCode) {
// In debug mode, log the status
Log.d(TAG + ".servicesConnected()", "Google Play services is available.");
// Continue
return true;
// Google Play services was not available for some reason
} else {
Log.d(TAG + ".servicesConnected()", "Google Play services is unavailable or outdated: " + resultCode);
// Get the error dialog from Google Play services
try {
GooglePlayServicesUtil.getErrorDialog(resultCode, activity, CONNECTION_FAILURE_RESOLUTION_REQUEST).show();
} catch (Exception e) {
Log.e("Error: GooglePlayServiceUtil: ", "" + e);
}
/**
Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(resultCode, activity, CONNECTION_FAILURE_RESOLUTION_REQUEST);
// If Google Play services can provide an error dialog
if (errorDialog != null) {
// Create a new DialogFragment for the error dialog
ErrorDialogFragment errorFragment = new ErrorDialogFragment();
// Set the dialog in the DialogFragment
errorFragment.setDialog(errorDialog);
// Show the error dialog in the DialogFragment
errorFragment.show(activity.getSupportFragmentManager(),"Location Updates");
}*/
return false;
}
}
The corresponding Activity is:
public class LocationTest extends FragmentActivity implements LocationListener {
private static final String TAG = LocationTest.class.getSimpleName();
private int count = 0;
private TextView lat;
private TextView lng;
private TextView quality;
private TextView conState;
private TextView refreshCount;
private TextView distance;
private LocationFragment locFrag;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.locationtest);
FragmentManager fManager = getSupportFragmentManager();
locFrag = new LocationFragment();
FragmentTransaction ft = fManager.beginTransaction();
ft.replace(R.id.map, locFrag);
ft.addToBackStack(null);
ft.commit();
locFrag.setGoal(Double.valueOf(8.83749747285), Double.valueOf(53.0663656578));
lat = (TextView) findViewById(R.id.curLat);
lng = (TextView) findViewById(R.id.curLng);
quality = (TextView) findViewById(R.id.curQuality);
conState = (TextView) findViewById(R.id.conState);
refreshCount = (TextView) findViewById(R.id.count);
distance = (TextView) findViewById(R.id.distance);
}
public void refreshLocation(View v) {
locFrag.refreshLocation(v);
}
public void toggleUpdates(View v) {
locFrag.toggleUpdates(v);
}
public void onLocationChanged(Location location) {
// Let the location parent know about the location change
// super.onLocationChanged(location);
count++;
lat.setText(Double.toString(locFrag.getCurrentLatitude()));
lng.setText(Double.toString(locFrag.getCurrentLongitude()));
quality.setText(Float.toString(locFrag.getAccuracy()));
conState.setText(Boolean.toString(locFrag.isConnected()));
refreshCount.setText(Integer.toString(count));
distance.setText(Float.toString(locFrag.getDistance()));
}
#Override
protected void onStart() {
super.onStart();
Log.d(TAG, "onStart()");
}
#Override
protected void onPause() {
super.onPause();
Log.d(TAG, "onPause()");
}
#Override
protected void onStop() {
super.onStop();
Log.d(TAG, "onStop()");
}
#Override
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume()");
}
}
I wonder if it is possible to get the ErrorDialog suggested by google to work from that SupportMapFragment to be able to handle the error or else stop the inflation of the fragment and return to the previous activity
any help appreciated :)
Use this code in present class which is capturing the location
currentLocation is the location Object
Intent intent = new Intent(this,target.class)
Bundle b = new Bundle();
b.putParcelable("Location", currentLocation);
i.putExtra("Location", b);
startActivity(i);
Receive Activity code:
b = getArguments();
Location location = b.getParcelable("Location");
By this way you can pass the location.I think it may be useful to you.

my Google+1 button is grayed out and not working?

i was trying to integrate G+ button in ma app.The G+ buttons grayed out.and its not counting.how to turns red ?
public class HomeActivity extends SherlockActivity implements ConnectionCallbacks, OnConnectionFailedListener{
private static final String URL = "https://play.google.com/store/apps/details?id=com.phoneix.allu";
private static final int PLUS_ONE_REQUEST_CODE = 0;
private static final int REQUEST_CODE_RESOLVE_ERR = 9000;
private ProgressDialog mConnectionProgressDialog;
private PlusClient mPlusClient;
private ConnectionResult mConnectionResult;
private PlusOneButton mPlusOneStandardButton;
#Override
public void onCreate(Bundle pBundle) {
super.onCreate(pBundle);
setContentView(R.layout.dashboard);
mPlusOneStandardButton = (PlusOneButton) findViewById(R.id.plus_one_standard_button);
mPlusClient = new PlusClient.Builder(this, this, this)
.build();
}
#Override
public void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
#Override
protected void onResume() {
super.onResume();
// Refresh the state of the +1 button each time we receive focus.
mPlusOneStandardButton.initialize(URL, PLUS_ONE_REQUEST_CODE);
}
#Override
public void onDisconnected() {
// Nothing to do.
}
#Override
public void onConnectionFailed(ConnectionResult result) {
if (mConnectionProgressDialog.isShowing()) {
// The user clicked the sign-in button already. Start to resolve
// connection errors. Wait until onConnected() to dismiss the
// connection dialog.
if (result.hasResolution()) {
try {
result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
mPlusClient.connect();
}
}
}
// Save the intent so that we can start an activity when the user clicks
// the sign-in button.
mConnectionResult = result;
}
public void onConnected(Bundle connectionHint) {
mPlusOneStandardButton.initialize(URL, PLUS_ONE_REQUEST_CODE);
}
#Override
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
if (requestCode == REQUEST_CODE_RESOLVE_ERR && responseCode == RESULT_OK) {
mConnectionResult = null;
mPlusClient.connect();
}
}
}
Try out this:
In xml file:
<com.google.android.gms.common.SignInButton
android:id="#+id/sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="92dp" >
</com.google.android.gms.common.SignInButton>
</RelativeLayout>
In your activity get that button:
#Override
public void onCreate(Bundle pBundle) {
super.onCreate(pBundle);
setContentView(R.layout.dashboard);
findViewById(R.id.sign_in_button).setOnClickListener(new OnClickListener() {
#Override
public void onClick
(View v) {
Intent i = new Intent(getApplicationContext(),YourActivity.class);
startActivity(i);
}
});
}
The problem is with the latest update of google play services.
Once I uninstalled all updates of google play services from app's settings,all +1 buttons are showing up fine.
Let's hope google will fix their update.
The new Google Play update changed the interface of the plusOne button, hence breaking all plusOne button based on the "old" Google play service SDK.
If you checkout their samples, you'll discover they have changed the interface for the plusOnButton.initialize, which no longer takes a "plusOneClient", but a URL.
To fix, download the latest (v13) Google Play Services using your "Android SDK Manager", and import it back to your project.

Categories

Resources