3

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

以下是我的代码:

@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);
    }

}
4

1 回答 1

0

我在 SDK 13 上注意到的是,当您为您的网站 +1 时,应用程序中没有考虑到它(可能是一种错误)。不过,当您在应用程序中 +1 时,会出现一个窗口:

  • 如果您单击确定,请在您的网站上添加 +1
  • 如果您点击取消,请删除您网站上的 +1
于 2013-11-07T14:54:55.073 回答