Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 添加google登录按钮-登录问题_Android_Google Plus - Fatal编程技术网

Android 添加google登录按钮-登录问题

Android 添加google登录按钮-登录问题,android,google-plus,Android,Google Plus,我正在尝试在我的android应用程序中加入谷歌登录按钮。 我从中获取了参考,它显示了我的持续进度条,并且没有登录到我的帐户。 我已经在emulator上添加了我的id。 我附上它的图像。 这是我的密码 public class MyActivity extends Activity implements GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListene

我正在尝试在我的android应用程序中加入谷歌登录按钮。 我从中获取了参考,它显示了我的持续进度条,并且没有登录到我的帐户。 我已经在emulator上添加了我的id。 我附上它的图像。 这是我的密码

public class MyActivity extends Activity implements GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener, View.OnClickListener {

    private static final String TAG = "ExampleActivity";
    private static final int REQUEST_CODE_RESOLVE_ERR = 9000;

    private ProgressDialog mConnectionProgressDialog;
    private PlusClient mPlusClient;
    private ConnectionResult mConnectionResult;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mPlusClient = new PlusClient.Builder(this, this, this)
                .setActions("http://schemas.google.com/AddActivity", "http://schemas.google.com/BuyActivity")
                .build();
        findViewById(R.id.sign_in_button).setOnClickListener(this);
        mConnectionProgressDialog = new ProgressDialog(this);
        mConnectionProgressDialog.setMessage("Signing in...");
    }


    @Override
    public void onConnected(Bundle bundle) {
        // We've resolved any connection errors.
        mConnectionProgressDialog.dismiss();
        Toast.makeText(this, " User is connected.", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onDisconnected() {
        Log.d(TAG, "disconnected");
    }

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {
        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 (connectionResult.hasResolution()) {
                try {
                    connectionResult.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
                } catch (IntentSender.SendIntentException e) {
                    mPlusClient.connect();
                }
            }
        }

        // Save the intent so that we can start an activity when the user clicks
        // the sign-in button.
        mConnectionResult = connectionResult;
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.sign_in_button && !mPlusClient.isConnected()) {
            if (mConnectionResult == null) {
                mConnectionProgressDialog.show();
            } else {
                try {
                    mConnectionResult.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
                } catch (IntentSender.SendIntentException e) {
                    // Try connecting again.
                    mConnectionResult = null;
                    mPlusClient.connect();
                }
            }
        }
    }

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

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">


    <com.google.android.gms.common.SignInButton
            android:id="@+id/sign_in_button"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"/>
</RelativeLayout>

androidmanifest.xml

![<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.GooglePlusDemo"
          android:versionCode="1"
          android:versionName="1.0">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.GET_ACCOUNTS"/>
    <uses-permission android:name="android.permission.USE_CREDENTIALS"/>


    <application
            android:label="@string/app_name"
            android:icon="@drawable/ic_launcher">
        <meta-data
                android:name="com.google.android.gms.version"
                android:value="@integer/google_play_services_version"/>
        <activity
                android:name="MyActivity"
                android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>

        </activity>
    </application>
</manifest>]
![
]

即使在控制台中打开GoogleAPI,它也会显示错误 我的设备上已经安装了google+应用程序。 我张贴这两张图片

mpluclient.connect()未在任何位置被调用。
您只是在单击事件中显示进度条,而不是尝试连接

来自Plusclient doc

您应该在活动的onCreate(Bundle)方法中实例化此对象,然后在onStart()中调用connect(),在onStop()中调用disconnect(),而不管状态如何


尝试在启动或单击按钮时添加MPluClient。

将imulator的播放序列更新为3.1,至少更新一次plz尝试在真实设备上测试其工作正常无问题如何在emulator中更新?我没有真正的设备me@DigveshPatel我检查了真实的设备,但同样的问题。嘿,完成了。我在模拟器中测试。当我在真正的设备上运行时,它工作得非常好。但是如何在登录按钮上显示用户的id,就像文本一样abc@gmail.com我想没有直接的方法。不起作用,已经在尝试,是的,没有直接的方法。谢谢你的帮助