Android和网站之间的Google Plus一键式一致性

时间:2013-09-10 20:36:20

标签: android google-plus-one

我已经按照谷歌播放服务示例在我的Android应用程序中添加了一个PlusOneButton,加号和减号功能到目前为止运行良好。只是当用户通过他们的+1网站删除加上项目时出现问题(它位于个人资料 - > 1 + 1)并返回应用程序,加号状态将不会在我的应用程序中更新,它将保持加号状态。 (看起来Play商店会将状态更改为un-plus)。我不知道Play商店是怎么做的。有人能给我一些建议吗?还有什么方法可以实现+1功能,就像Play商店一样?不必显示弹出对话框。

以下是我的代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.plustest);

    int errorCode = GooglePlusUtil.checkGooglePlusApp(this);
    if(errorCode != GooglePlusUtil.SUCCESS) {
        GooglePlusUtil.getErrorDialog(errorCode, this, 0).show();
    } else {
        // The +1 button does not require scopes.
        mPlusClient = new PlusClient.Builder(this, this, this)
             .clearScopes()
             .build();
    }

    /*
     * The {@link PlusOneButton} can be configured in code, but in this example we
     * have set the parameters in the layout.
     *
     * Example:
     * mPlusOneSmallButton.setAnnotation(PlusOneButton.ANNOTATION_INLINE);
     * mPlusOneSmallButton.setSize(PlusOneButton.SIZE_MEDIUM);
     */
    mPlusOneSmallButton = (PlusOneButton) findViewById(R.id.plus_one_small_button);
    mPlusOneMediumButton = (PlusOneButton) findViewById(R.id.plus_one_medium_button);
    mPlusOneTallButton = (PlusOneButton) findViewById(R.id.plus_one_tall_button);
    mPlusOneStandardButton = (PlusOneButton) findViewById(R.id.plus_one_standard_button);
    mPlusOneStandardButtonWithAnnotation = (PlusOneButton) findViewById(
         R.id.plus_one_standard_ann_button);

}


@Override
protected void onStart() {
    super.onStart();
    mPlusClient.connect();
}


@Override
protected void onResume() {
    super.onResume();
    // Refresh the state of the +1 button each time we receive focus.
    mPlusOneSmallButton.initialize(mPlusClient, URL, PLUS_ONE_REQUEST_CODE);
    mPlusOneMediumButton.initialize(mPlusClient, URL, this);
    mPlusOneTallButton.initialize(mPlusClient, URL, PLUS_ONE_REQUEST_CODE);
    mPlusOneStandardButton.initialize(mPlusClient, URL, PLUS_ONE_REQUEST_CODE);
    mPlusOneStandardButtonWithAnnotation.initialize(mPlusClient, URL, PLUS_ONE_REQUEST_CODE);
}


@Override
protected void onStop() {
    super.onStop();
    mPlusClient.disconnect();
}


@Override
public void onClick(View v) {
}

@Override
public void onButtonClick(int id) {

}

@Override
public void onDashboardClick() {

}

@Override
public void onConnected(Bundle bundle) {
    String name = mPlusClient.getAccountName();
}

@Override
public void onDisconnected() {

}

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
    mConnectionResult = connectionResult;

    if(!mPlusClient.isConnected()) {
        try {
            mConnectionResult.startResolutionForResult(this, PLUS_ONE_REQUEST_CODE);
        } catch (IntentSender.SendIntentException e) {
            mConnectionResult = null;
            mPlusClient.connect();
        }
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent){
    if(requestCode == PLUS_ONE_REQUEST_CODE && resultCode == RESULT_OK) {
        mConnectionResult = null;
        mPlusClient.connect();
    }
}

@Override
public void onPlusOneClick(Intent intent) {
    if(!mPlusClient.isConnected()) {
        mPlusClient.connect();
    } else {
        startActivityForResult(intent, 0);
    }

}

1 个答案:

答案 0 :(得分:0)

我在SDK 13上注意到的是,当您为自己的网站+1时,它不会在应用程序中被考虑(可能是一种bug)。然而,当你在应用程序中+1时,会出现一个窗口:

  • 如果点击“确定”,则在您的网站上添加+1
  • 如果您点击取消
  • ,请删除您网站上的+1