2014-02-08 55 views
0

我在Google+按鈕集成中遇到了這個問題。在logcat或強制關閉中沒有錯誤,但有些不對。我添加了按鈕,你可以在下面看到我的XML。當我離線時它是灰色的,當我在線時是紅白色的,所以我想這很好。你也可以嘻嘻我的java代碼的按鈕。問題是,當我點擊它時,它會打開一個彈出窗口,其中包含我的Google +名稱一秒鐘,之後出現一個錯誤,您可以在屏幕截圖中看到該錯誤。我模糊了我的名字。因此,這裏的屏幕:Google+按鈕集成...出了點問題

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

      } 
} 

回答