Google+的按钮集成...什么是错的 [英] Google+ button integration...something is wrong

查看:147
本文介绍了Google+的按钮集成...什么是错的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个问题的Google+按钮的集成。有一个在logcat中或强制关闭没有错误,但东西是不正确的。我添加的按钮,你可以看到下面我的XML。它是灰色的,当我下线,红白色时,我在线上,所以我想这是很好的。您也可以熙我的Java $ C $下按钮。问题是,当我点击它,它的开放与我的谷歌+的名字一秒钟,只是在那之后我得到一个错误,你可以在截图娄看到一个弹出。我所迷离我的名字。因此,这里的屏幕:

和我的XML:

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    的xmlns:加=htt​​p://schemas.android.com/apk/lib/com.google.android.gms.plus
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:背景=@可绘制/ bac2k
    机器人:重力=中心|顶
    机器人:方向=垂直
    工具:上下文的xmlns =Plusone。:程序=htt​​p://schemas.android.com/apk/res-auto>

    <的LinearLayout
        机器人:ID =@ + ID / LA2
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:重力=中心
        机器人:方向=垂直
        机器人:能见度=有形与GT;

         <的TextView
        机器人:ID =@ + ID / textView2
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_marginBottom =25dp
        机器人:文本=点击+1按钮,然后点击OK
        机器人:textAppearance =:/>中的Andr​​oid ATTR / textAppearanceLarge?

    < com.google.android.gms.plus.PlusOneButton
        的xmlns:加=htt​​p://schemas.android.com/apk/lib/com.google.android.gms.plus
        机器人:ID =@ + ID / plus_one_button
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_marginBottom =20dp
        加:注释=内联
        加:大小=标准>

    < /com.google.android.gms.plus.PlusOneButton>

    <的TextView
        机器人:ID =@ + ID / textView1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_marginTop =25dp
        机器人:文本=或等待:
        机器人:textAppearance =:/>中的Andr​​oid ATTR / textAppearanceLarge?
    < / LinearLayout中>

< / LinearLayout中>
 

和我的Java code:

 公共类Plusone扩展活动实现ConnectionCallbacks,OnConnectionFailedListener {

意向意图;
TextView的licznik,称号;
PendingIntent pintent;
INT状态;
私有静态最终诠释PLUS_ONE_REQUEST_ code = 0;
私有静态最终诠释REQUEST_ code_RESOLVE_ERR = 9000;
   私人ProgressDialog mConnectionProgressDialog;
   私人PlusClient mPlusClient;
   私人ConnectionResult mConnectionResult;
   私人PlusOneButton mPlusOneMediumButton;
   INT秒;
   的LinearLayout lay2;
   处理器韩;

    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
         mPlusClient =新PlusClient.Builder(这个,这​​个,这个)
            .clearScopes()
            。建立();
        的setContentView(R.layout.plusone);
          mPlusOneMediumButton =(PlusOneButton)findViewById(R.id.plus_one_button);

        状态= 0;

         秒= 15;
         licznik =(TextView中)findViewById(R.id.textView1);
            lay2 =(的LinearLayout)findViewById(R.id.la2);
            标题=(TextView中)findViewById(R.id.textView2);

            如果(国家== 1)
            {

                 lay2.setVisibility(View.GONE);
            }
            其他
            {
                韩=新的处理程序();
                han2.post(mUpdate);
            }
             mPlusOneMediumButton.initialize(mPlusClient,https://market.android.com/details?id=us.mypackageame.game",new OnPlusOneClickListener(){
                   @覆盖
                   公共无效onPlusOneClick(意向意图){
                   // TODO自动生成方法存根

                       状态= 1;
                      mPlusOneMediumButton.setVisibility(View.INVISIBLE);
                      title.setVisibility(View.GONE);
                       title.setVisibility(View.GONE);

                   startActivityForResult(意向,PLUS_ONE_REQUEST_ code);
                   }
                   });

    }

             公共无效onConnectionFailed(ConnectionResult结果){
                 如果(mConnectionProgressDialog.isShowing()){
                         //用户点击登录按钮了。开始解决
                         //连接错误。等到onConnected()驳回
                         //连接对话框。
                         如果(result.hasResolution()){
                                 尝试 {
                                         result.startResolutionForResult(这一点,REQUEST_ code_RESOLVE_ERR);
                                 }赶上(SendIntentException E){
                                         mPlusClient.connect();
                                 }
                         }
                 }

                 //保存的目的,使我们可以开始一个活动,当用户点击
                 //在登录按钮。
                 mConnectionResult =结果;
          }


         @覆盖
         公共无效onDisconnected(){
            // TODO自动生成方法存根

         }
         @覆盖
         保护无效onActivityResult(INT申请code,INT响应code,意图意图){
            如果(要求code == REQUEST_ code_RESOLVE_ERR和放大器;&安培;响应code == RESULT_OK){
                mConnectionResult = NULL;
                mPlusClient.connect();
            }

         }
         @覆盖
            保护无效的OnStart(){
                super.onStart();
                mPlusClient.connect();
            }

            @覆盖
            保护无效的onStop(){
                super.onStop();
                mPlusClient.disconnect();
            }
            私人可运行mUpdate =新的Runnable(){
                   公共无效的run(){




                       han2.postDelayed(这一点,1000);
                       秒=秒-1;
                       licznik.setText(或等待:+ Integer.toString(秒)+秒);
                    如果(SEC< = 0)
                    {
                    han2.removeCallbacks(mUpdate);

                 lay2.setVisibility(View.GONE);

                 startActivity(新的意向书(us.mypackageame.game.MENU));
                 完();

                    }
                    }

                };

            @覆盖
            公共无效onConnected(){
                串帐户名= mPlusClient.getAccountName();
                  // Toast.makeText(这一点,帐户名+连接,Toast.LENGTH_LONG).show();

            }
}
 

解决方案

该版本的PlusOneButton初始化的是一个老 - 尽量确保您使用的是最新的谷歌播放服务,并从电话中删除PlusClient - 见的http://developer.android.com/reference/com/google/android/gms/plus/PlusOneButton.html

我也不能确定URL是否会做,你可能想要什么,并+1 Play商店的应用程序,我认为它会只是+1 URL本身(这可能不会在任何地方显示的)。

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).

这篇关于Google+的按钮集成...什么是错的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆