【问题标题】:Google Plus One Button Consistency between Android and WebsiteAndroid 和网站之间的 Google Plus One Button 一致性
【发布时间】:2013-09-10 20:36:20
【问题描述】:

我已经按照 google play 服务示例在我的 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);
    }

}

【问题讨论】:

    标签: android google-plus-one


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-21
      • 1970-01-01
      • 2011-12-23
      • 2017-06-14
      • 2021-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多