Google+按钮集成...出了点问题

时间:2014-02-08 16:25:59

标签: java android google-plus

我在Google+按钮集成方面存在此问题。 logcat或强制关闭没有错误,但有些事情是不对的。我添加了按钮,您可以在下面看到我的XML。当我离线时它是灰色的,当我在线时它是红白色的,所以我猜这很好。你也可以告诉我的java代码按钮。问题是,当我点击它时,它打开一个带有我的谷歌+名称的弹出窗口一秒钟,然后我得到一个错误,你可以在下面的屏幕截图中看到。我模糊了我的名字。所以这是屏幕:

enter image description here

我的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>

我的java代码:

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();

            }
}

1 个答案:

答案 0 :(得分:0)

PlusOneButton初始化程序的版本是旧版本 - 尝试确保您使用最新的Google Play服务,并从通话中删除PlusClient - 请参阅http://developer.android.com/reference/com/google/android/gms/plus/PlusOneButton.html

我也不确定这个网址是否能满足您的需求,并且在Play商店中为应用程序+1,我认为它只会+1网址本身(可能不会在任何地方显示)。