I have this problem with Google+ button integration. There's no error in logcat or force close, but something is not right. I added the button, you can see my XML below. It's grey when i'm offline, and red-white when I'm online, so I guess that's good. You can also hee my java code for the button. The problem is, when I click it, it open's a popup with my google+ name for a second and just after that I get an error, which you can see on the screenshot bellow. I blured my name. So here's the screen:
And my XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bac2k"
android:gravity="center|top"
android:orientation="vertical"
tools:context=".Plusone" xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:id="@+id/la2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:visibility="visible" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:text="Click +1 button and tap OK"
android:textAppearance="?android:attr/textAppearanceLarge" />
<com.google.android.gms.plus.PlusOneButton
xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
android:id="@+id/plus_one_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
plus:annotation="inline"
plus:size="standard" >
</com.google.android.gms.plus.PlusOneButton>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:text="Or wait:"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</LinearLayout>
And my java code:
public class Plusone extends Activity implements ConnectionCallbacks, OnConnectionFailedListener {
Intent intent;
TextView licznik,title;
PendingIntent pintent;
int state;
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 mPlusOneMediumButton;
int sec;
LinearLayout lay2;
Handler han2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPlusClient = new PlusClient.Builder(this, this, this)
.clearScopes()
.build();
setContentView(R.layout.plusone);
mPlusOneMediumButton = (PlusOneButton) findViewById(R.id.plus_one_button);
state=0;
sec=15;
licznik=(TextView)findViewById(R.id.textView1);
lay2=(LinearLayout)findViewById(R.id.la2);
title=(TextView)findViewById(R.id.textView2);
if(state==1)
{
lay2.setVisibility(View.GONE);
}
else
{
han2 = new Handler();
han2.post(mUpdate);
}
mPlusOneMediumButton.initialize(mPlusClient, "https://market.android.com/details?id=us.mypackageame.game",new OnPlusOneClickListener() {
@Override
public void onPlusOneClick(Intent intent) {
// TODO Auto-generated method stub
state=1;
mPlusOneMediumButton.setVisibility(View.INVISIBLE);
title.setVisibility(View.GONE);
title.setVisibility(View.GONE);
startActivityForResult(intent, PLUS_ONE_REQUEST_CODE);
}
});
}
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;
}
@Override
public void onDisconnected() {
// TODO Auto-generated method stub
}
@Override
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
if (requestCode == REQUEST_CODE_RESOLVE_ERR && responseCode == RESULT_OK) {
mConnectionResult = null;
mPlusClient.connect();
}
}
@Override
protected void onStart() {
super.onStart();
mPlusClient.connect();
}
@Override
protected void onStop() {
super.onStop();
mPlusClient.disconnect();
}
private Runnable mUpdate = new Runnable() {
public void run() {
han2.postDelayed(this, 1000);
sec=sec-1;
licznik.setText("Or wait: "+ Integer.toString(sec)+" seconds");
if (sec<=0)
{
han2.removeCallbacks(mUpdate);
lay2.setVisibility(View.GONE);
startActivity(new Intent("us.mypackageame.game.MENU"));
finish();
}
}
};
@Override
public void onConnected() {
String accountName = mPlusClient.getAccountName();
// Toast.makeText(this, accountName + " is connected.", Toast.LENGTH_LONG).show();
}
}
That version of the PlusOneButton initializer is an old one - try making sure you're on the latest Google Play services, and remove the PlusClient from the call - see http://developer.android.com/reference/com/google/android/gms/plus/PlusOneButton.html
I'm also not sure whether that URL will do what you probably want and +1 the app in the Play store, I think it'll just +1 the URL itself (which probably wont be displayed anywhere).