Android 不幸的是,G+;登录已停止工作

Android 不幸的是,G+;登录已停止工作,android,login,google-plus,Android,Login,Google Plus,我是android的初学者,如果我错了,请指导我 我已经从下载了源代码,以便在我的应用程序中集成google+登录 完成的步骤: 1) 已导入已下载的android源代码 2) 从下面的路径导入google play服务库,并将其作为我当前项目的库,因为代码提供了库 C:\Users\user\android-sdks\extras\google\google_play_services\libproject\google-play-services_lib 3) 当我运行apk文件时,我抛出

我是android的初学者,如果我错了,请指导我

我已经从下载了源代码,以便在我的应用程序中集成google+登录

完成的步骤:

1) 已导入已下载的android源代码

2) 从下面的路径导入google play服务库,并将其作为我当前项目的库,因为代码提供了库

C:\Users\user\android-sdks\extras\google\google_play_services\libproject\google-play-services_lib
3) 当我运行apk文件时,我抛出了一个错误
,不幸的是,G+登录已停止工作

我没有得到任何错误来追踪我的应用程序失败的地方

Manifest.xml:

     <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="info.androidhive.gpluslogin"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="18" />

    <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:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <activity
            android:name="info.androidhive.gpluslogin.MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

主要活动:

package info.androidhive.gpluslogin;

import java.io.InputStream;

import android.app.Activity;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.plus.Plus;
import com.google.android.gms.plus.model.people.Person;

public class MainActivity extends Activity implements OnClickListener,
        ConnectionCallbacks, OnConnectionFailedListener {

    private static final int RC_SIGN_IN = 0;
    // Logcat tag
    private static final String TAG = "MainActivity";

    // Profile pic image size in pixels
    private static final int PROFILE_PIC_SIZE = 400;

    // Google client to interact with Google API
    private GoogleApiClient mGoogleApiClient;

    /**
     * A flag indicating that a PendingIntent is in progress and prevents us
     * from starting further intents.
     */
    private boolean mIntentInProgress;

    private boolean mSignInClicked;

    private ConnectionResult mConnectionResult;

    private SignInButton btnSignIn;
    private Button btnSignOut, btnRevokeAccess;
    private ImageView imgProfilePic;
    private TextView txtName, txtEmail;
    private LinearLayout llProfileLayout;

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

        btnSignIn = (SignInButton) findViewById(R.id.btn_sign_in);
        btnSignOut = (Button) findViewById(R.id.btn_sign_out);
        btnRevokeAccess = (Button) findViewById(R.id.btn_revoke_access);
        imgProfilePic = (ImageView) findViewById(R.id.imgProfilePic);
        txtName = (TextView) findViewById(R.id.txtName);
        txtEmail = (TextView) findViewById(R.id.txtEmail);
        llProfileLayout = (LinearLayout) findViewById(R.id.llProfile);

        // Button click listeners
        btnSignIn.setOnClickListener(this);
        btnSignOut.setOnClickListener(this);
        btnRevokeAccess.setOnClickListener(this);

        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this).addApi(Plus.API, null)
                .addScope(Plus.SCOPE_PLUS_LOGIN).build();
    }

    protected void onStart() {
        super.onStart();
        mGoogleApiClient.connect();
    }

    protected void onStop() {
        super.onStop();
        if (mGoogleApiClient.isConnected()) {
            mGoogleApiClient.disconnect();
        }
    }

    /**
     * Method to resolve any signin errors
     * */
    private void resolveSignInError() {
        if (mConnectionResult.hasResolution()) {
            try {
                mIntentInProgress = true;
                mConnectionResult.startResolutionForResult(this, RC_SIGN_IN);
            } catch (SendIntentException e) {
                mIntentInProgress = false;
                mGoogleApiClient.connect();
            }
        }
    }

    @Override
    public void onConnectionFailed(ConnectionResult result) {
        if (!result.hasResolution()) {
            GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this,
                    0).show();
            return;
        }

        if (!mIntentInProgress) {
            // Store the ConnectionResult for later usage
            mConnectionResult = result;

            if (mSignInClicked) {
                // The user has already clicked 'sign-in' so we attempt to
                // resolve all
                // errors until the user is signed in, or they cancel.
                resolveSignInError();
            }
        }

    }

    @Override
    protected void onActivityResult(int requestCode, int responseCode,
            Intent intent) {
        if (requestCode == RC_SIGN_IN) {
            if (responseCode != RESULT_OK) {
                mSignInClicked = false;
            }

            mIntentInProgress = false;

            if (!mGoogleApiClient.isConnecting()) {
                mGoogleApiClient.connect();
            }
        }
    }

    @Override
    public void onConnected(Bundle arg0) {
        mSignInClicked = false;
        Toast.makeText(this, "User is connected!", Toast.LENGTH_LONG).show();

        // Get user's information
        getProfileInformation();

        // Update the UI after signin
        updateUI(true);

    }

    /**
     * Updating the UI, showing/hiding buttons and profile layout
     * */
    private void updateUI(boolean isSignedIn) {
        if (isSignedIn) {
            btnSignIn.setVisibility(View.GONE);
            btnSignOut.setVisibility(View.VISIBLE);
            btnRevokeAccess.setVisibility(View.VISIBLE);
            llProfileLayout.setVisibility(View.VISIBLE);
        } else {
            btnSignIn.setVisibility(View.VISIBLE);
            btnSignOut.setVisibility(View.GONE);
            btnRevokeAccess.setVisibility(View.GONE);
            llProfileLayout.setVisibility(View.GONE);
        }
    }

    /**
     * Fetching user's information name, email, profile pic
     * */
    private void getProfileInformation() {
        try {
            if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
                Person currentPerson = Plus.PeopleApi
                        .getCurrentPerson(mGoogleApiClient);
                String personName = currentPerson.getDisplayName();
                String personPhotoUrl = currentPerson.getImage().getUrl();
                String personGooglePlusProfile = currentPerson.getUrl();
                String email = Plus.AccountApi.getAccountName(mGoogleApiClient);

                Log.e(TAG, "Name: " + personName + ", plusProfile: "
                        + personGooglePlusProfile + ", email: " + email
                        + ", Image: " + personPhotoUrl);

                txtName.setText(personName);
                txtEmail.setText(email);

                // by default the profile url gives 50x50 px image only
                // we can replace the value with whatever dimension we want by
                // replacing sz=X
                personPhotoUrl = personPhotoUrl.substring(0,
                        personPhotoUrl.length() - 2)
                        + PROFILE_PIC_SIZE;

                new LoadProfileImage(imgProfilePic).execute(personPhotoUrl);

            } else {
                Toast.makeText(getApplicationContext(),
                        "Person information is null", Toast.LENGTH_LONG).show();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onConnectionSuspended(int arg0) {
        mGoogleApiClient.connect();
        updateUI(false);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    /**
     * Button on click listener
     * */
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.btn_sign_in:
            // Signin button clicked
            signInWithGplus();
            break;
        case R.id.btn_sign_out:
            // Signout button clicked
            signOutFromGplus();
            break;
        case R.id.btn_revoke_access:
            // Revoke access button clicked
            revokeGplusAccess();
            break;
        }
    }

    /**
     * Sign-in into google
     * */
    private void signInWithGplus() {
        if (!mGoogleApiClient.isConnecting()) {
            mSignInClicked = true;
            resolveSignInError();
        }
    }

    /**
     * Sign-out from google
     * */
    private void signOutFromGplus() {
        if (mGoogleApiClient.isConnected()) {
            Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
            mGoogleApiClient.disconnect();
            mGoogleApiClient.connect();
            updateUI(false);
        }
    }

    /**
     * Revoking access from google
     * */
    private void revokeGplusAccess() {
        if (mGoogleApiClient.isConnected()) {
            Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
            Plus.AccountApi.revokeAccessAndDisconnect(mGoogleApiClient)
                    .setResultCallback(new ResultCallback<Status>() {
                        @Override
                        public void onResult(Status arg0) {
                            Log.e(TAG, "User access revoked!");
                            mGoogleApiClient.connect();
                            updateUI(false);
                        }

                    });
        }
    }

    /**
     * Background Async task to load user profile picture from url
     * */
    private class LoadProfileImage extends AsyncTask<String, Void, Bitmap> {
        ImageView bmImage;

        public LoadProfileImage(ImageView bmImage) {
            this.bmImage = bmImage;
        }

        protected Bitmap doInBackground(String... urls) {
            String urldisplay = urls[0];
            Bitmap mIcon11 = null;
            try {
                InputStream in = new java.net.URL(urldisplay).openStream();
                mIcon11 = BitmapFactory.decodeStream(in);
            } catch (Exception e) {
                Log.e("Error", e.getMessage());
                e.printStackTrace();
            }
            return mIcon11;
        }

        protected void onPostExecute(Bitmap result) {
            bmImage.setImageBitmap(result);
        }
    }

}
package info.androidhive.gpluslogin;
导入java.io.InputStream;
导入android.app.Activity;
导入android.content.Intent;
导入android.content.IntentSender.SendIntentException;
导入android.graphics.Bitmap;
导入android.graphics.BitmapFactory;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.Menu;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.widget.Button;
导入android.widget.ImageView;
导入android.widget.LinearLayout;
导入android.widget.TextView;
导入android.widget.Toast;
导入com.google.android.gms.common.ConnectionResult;
导入com.google.android.gms.common.GooglePlayServicesUtil;
导入com.google.android.gms.common.SignInButton;
导入com.google.android.gms.common.api.GoogleAppClient;
导入com.google.android.gms.common.api.GoogleAppClient.ConnectionCallbacks;
导入com.google.android.gms.common.api.GoogleAppClient.OnConnectionFailedListener;
导入com.google.android.gms.common.api.ResultCallback;
导入com.google.android.gms.common.api.Status;
导入com.google.android.gms.plus.plus;
导入com.google.android.gms.plus.model.people.Person;
公共类MainActivity扩展活动实现OnClickListener,
ConnectionCallbacks,OnConnectionFailedListener{
私有静态最终int RC_SIGN_IN=0;
//Logcat标签
私有静态最终字符串TAG=“MainActivity”;
//配置文件pic图像大小(像素)
私有静态最终整数配置文件图片大小=400;
//Google客户端与Google API交互
私人GoogleapClient MGoogleapClient;
/**
*一种标志,表明悬挂式帐篷正在进行中并阻止我们
*从开始进一步的意图。
*/
私有布尔mIntentInProgress;
私有布尔msignincled;
私有连接结果mConnectionResult;
私人签名按钮;
专用按钮btnSignOut、btnRevokeAccess;
私有ImageView imgProfilePic;
私有文本视图txtName,txtmail;
专用线路布局图;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnSignIn=(签名按钮)findViewById(R.id.btn\u sign\u in);
btnSignOut=(按钮)findViewById(R.id.btn\u注销);
btnRevokeAccess=(按钮)findViewById(R.id.btn\u revoke\u访问);
imgProfilePic=(ImageView)findViewById(R.id.imgProfilePic);
txtName=(TextView)findViewById(R.id.txtName);
txtEmail=(TextView)findViewById(R.id.txtEmail);
llProfileLayout=(LinearLayout)findviewbyd(R.id.llProfile);
//按钮单击侦听器
btnSignIn.setOnClickListener(此);
btnSignOut.setOnClickListener(这个);
btnRevokeAccess.setOnClickListener(此);
mgoogleapclient=新的Googleapclient.Builder(此)
.addConnectionCallbacks(此)
.addOnConnectionFailedListener(this).addApi(Plus.API,null)
.addScope(Plus.SCOPE\u Plus\u LOGIN).build();
}
受保护的void onStart(){
super.onStart();
mGoogleApiClient.connect();
}
受保护的void onStop(){
super.onStop();
if(mgoogleapClient.isConnected()){
mGoogleApiClient.disconnect();
}
}
/**
*方法来解决任何登录错误
* */
私有无效解析错误(){
if(mcConnectionResult.hasResolution()){
试一试{
mIntentInProgress=true;
mConnectionResult.StartResult解决方案(这是RC\u登录);
}捕获(发送){
mIntentInProgress=false;
mGoogleApiClient.connect();
}
}
}
@凌驾
连接失败的公共void(连接结果){
如果(!result.hasResolution()){
GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(),此,
0)show();
返回;
}
如果(!mIntentInProgress){
//存储ConnectionResult供以后使用
mConnectionResult=结果;
如果(mSignInClicked){
//用户已单击“登录”,因此我们尝试
//解决所有问题
//错误,直到用户登录或取消。
ResolveSignError();
}
}
}
@凌驾
ActivityResult上的受保护无效(int请求代码、int响应代码、,
意图(意图){
if(requestCode==RC\u登录){
if(responseCode!=结果\u正常){
mSignInClicked=false;
}
mIntentInProgress=false;
如果(!mgoogleapClient.isConnecting()){
mGoogleApiClient.connect();
}
}
}
@凌驾
未连接的公共空间(捆绑arg0){
mSignInClicked=false;
Toast.makeText(此“用户已连接!”,Toast.LENGTH_LONG.show();
//获取用户信息
getProfileInformation();
//签名后更新用户界面
public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this).addApi(Plus.API)
                .addScope(Plus.SCOPE_PLUS_LOGIN).build();
    }

    @SuppressWarnings("deprecation")
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {

        case R.id.facebooklog:

            }
            break;
        case R.id.googlepluslog:

            mGoogleApiClient.connect();
            me = false;
            mSignedInClicked = true;
            signInWithGplus();
            break;

        }

    }

    @SuppressWarnings("static-access")
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (me) {
            super.onActivityResult(requestCode, resultCode, data);
            Session.getActiveSession().onActivityResult(getActivity(),
                    requestCode, resultCode, data);
        } else {
            if (requestCode == RC_SIGNIN) {
                Log.i("", "OnActivityResult");
                if (requestCode != getActivity().RESULT_OK) {
                    mSignedInClicked = false;

                }

                mIntentInProgress = false;

                if (!mGoogleApiClient.isConnecting()) {
                    mGoogleApiClient.connect();
                }
            }
        }

    }

    private void signInWithGplus() {
        // TODO Auto-generated method stub
        if (!mGoogleApiClient.isConnecting()) {
            mSignedInClicked = true;
            resolveSignInerror();
        }

    }

    private void resolveSignInerror() {
        // TODO Auto-generated method stub
        if (mConnectionResult.hasResolution()) {
            try {

                mIntentInProgress = true;
                mConnectionResult.startResolutionForResult(getActivity(),
                        RC_SIGNIN);

            } catch (SendIntentException e) {

                mIntentInProgress = false;
                mGoogleApiClient.connect();
            }
        }
    }

    @Override
    public void onConnectionFailed(ConnectionResult result) {
        // TODO Auto-generated method stub
        if (!result.hasResolution()) {
            GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(),
                    getActivity(), 0).show();
            return;
        }
        if (!mIntentInProgress) {

            mConnectionResult = result;
            if (mSignedInClicked) {
                resolveSignInerror();
            }
        }

    }

    @Override
    public void onConnected(Bundle arg0) {
        mSignedInClicked = false;
        Log.i("", "OnConnected");
        Toast.makeText(
                getActivity(),
                Plus.AccountApi.getAccountName(mGoogleApiClient)
                        + "  connected", Toast.LENGTH_SHORT).show();



    }

    @Override
    public void onConnectionSuspended(int arg0) {
        mGoogleApiClient.connect();

    }

    @Override
    public void onStart() {
        // TODO Auto-generated method stub
        super.onStart();
        mGoogleApiClient.connect();


    }

    @Override
    public void onStop() {
        // TODO Auto-generated method stub
        super.onStop();
        if (mGoogleApiClient.isConnected()) {
            mGoogleApiClient.disconnect();
        }
    }