android - Google Plus 一键安卓与网站一致性

标签 android google-plus-one

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

}

最佳答案

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

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

关于android - Google Plus 一键安卓与网站一致性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18728312/

相关文章:

java - Google 强制更新到最新的 OpenSSL

javascript - 从 Google +1 按钮共享时指定图像

javascript - Google +1 按钮未打开 "share this"气泡

android - 无需在 Android 上使用客户管理器即可对 Google API 进行 OAuth2.0 身份验证

android - Popup 出现在 DialogFragment 后面

javascript - Android 浏览器 orientationchange 事件不断触发

javascript - 动态添加谷歌+1按钮和IE8问题

android - 以下类无法实例化 : - com. google.android.gms.plus.PlusOneButton

google-plus - Google plus API 用于获取公司页面的 +1 计数

java - 在没有源代码的情况下使用 Espresso for APK 编写 UI 测试