通过Google Plus登录会破坏Android中的应用程序

时间:2014-05-21 11:07:40

标签: android google-plus google-play-services

我按照https://developers.google.com/+/mobile/android/getting-started?hl=es的步骤进行操作 我得到了示例PlusSampleActivity的工作原理。 现在,我尝试将代码复制到我的应用程序中,但运行在mPlusClient.connect(); 这是我的代码:

    public class Inicio extends Activity implements OnClickListener,
        PlusClient.ConnectionCallbacks, PlusClient.OnConnectionFailedListener, PlusClient.OnAccessRevokedListener{
    public static SQLiteDatabase db;
    static BDhelper dbhelper;
    private AdView adView;

    private static final int DIALOG_GET_GOOGLE_PLAY_SERVICES = 1;
    private static final int REQUEST_CODE_SIGN_IN = 1;
    private static final int REQUEST_CODE_GET_GOOGLE_PLAY_SERVICES = 2;
    private static final int REQUEST_CODE_RESOLVE_ERR = 3;

    private TextView mSignInStatus;
    private PlusClient mPlusClient;
    private SignInButton mSignInButton;
    private View mSignOutButton, mRevokeAccessButton;
    private ConnectionResult mConnectionResult;
    public static final HashMap<String, String> MOMENT_TYPES;

        public static final ArrayList<String> MOMENT_LIST;  // A list of moment target types.
        public static final String[] ACTIONS;
        static {
            MOMENT_TYPES = new HashMap<String, String>(9);
            MOMENT_TYPES.put("AddActivity",
                    "https://developers.google.com/+/plugins/snippet/examples/thing");
            MOMENT_TYPES.put("BuyActivity",
                    "https://developers.google.com/+/plugins/snippet/examples/a-book");
            MOMENT_TYPES.put("CheckInActivity",
                    "https://developers.google.com/+/plugins/snippet/examples/place");
            MOMENT_TYPES.put("CommentActivity",
                    "https://developers.google.com/+/plugins/snippet/examples/blog-entry");
            MOMENT_TYPES.put("CreateActivity",
                    "https://developers.google.com/+/plugins/snippet/examples/photo");
            MOMENT_TYPES.put("ListenActivity",
                    "https://developers.google.com/+/plugins/snippet/examples/song");
            MOMENT_TYPES.put("ReserveActivity",
                    "https://developers.google.com/+/plugins/snippet/examples/restaurant");
            MOMENT_TYPES.put("ReviewActivity",
                    "https://developers.google.com/+/plugins/snippet/examples/widget");

            MOMENT_LIST = new ArrayList<String>(MOMENT_TYPES.keySet());
            Collections.sort(MOMENT_LIST);

            ACTIONS = MOMENT_TYPES.keySet().toArray(new String[0]);
            int count = ACTIONS.length;
            for (int i = 0; i < count; i++) {
                ACTIONS[i] = "http://schemas.google.com/" + ACTIONS[i];
            }
        }

    protected ScreenOrientation getScreenOrientation() {
        return ScreenOrientation.LANDSCAPE; //Pantalla apaisada
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {//LLEGA AQUI PRIMERO
        super.onCreate(savedInstanceState); //null
        setContentView(R.layout.activity_juego);

        final Button btnJugar = (Button)findViewById(R.id.bJugar);
        final Button btnSalir = (Button)findViewById(R.id.bSalir);
        final Button btnHighScores = (Button)findViewById(R.id.bHighScores);

        mPlusClient = new PlusClient.Builder(this, this, this).setActions(ACTIONS).build();
        /*mPlusClient = new PlusClient.Builder(this, this, this)
        .setVisibleActivities("http://schemas.google.com/AddActivity", "http://schemas.google.com/BuyActivity")
        .build();
        mPlusClient = new PlusClient.Builder(this, this, this)
        .setActions("http://schemas.google.com/AddActivity", "http://schemas.google.com/BuyActivity")
        .build();*/


        dbhelper = new BDhelper(this, "BaseDatos", null, 1); //No entra a crearla, salvo la primera vez
        db = dbhelper.getWritableDatabase();
    }
    @Override
    protected void onDestroy(){//se llama autom al dar al botón de atrás
        super.onDestroy();
          if (adView != null) {
            adView.destroy();
          }
          super.onDestroy();
        System.exit(0);
    }    
/*
    @Override
    public void onConfigurationChanged(Configuration newConfig) {//Para los giros de pantalla esto y en el manifest android:configChanges
        super.onConfigurationChanged(newConfig);
    }*/

    @Override
    public void onStart() {//ENTRA DESPUÉS DEL ON CREATE
        super.onStart();
        mPlusClient.connect();  //PETA
        Toast.makeText(this, "Connectting...", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onStop() {
        mPlusClient.disconnect();
        super.onStop();
    }

    public void onClick(View view) {
        switch(view.getId()) {
            case R.id.sign_in_button:
                int available = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
                if (available != ConnectionResult.SUCCESS) {
                    showDialog(DIALOG_GET_GOOGLE_PLAY_SERVICES);
                    return;
                }

                try {
                    mSignInStatus.setText(getString(R.string.signing_in_status));
                    mConnectionResult.startResolutionForResult(this, REQUEST_CODE_SIGN_IN);
                } catch (IntentSender.SendIntentException e) {
                    // Fetch a new result to start.
                    mPlusClient.connect();
                }
                break;
            case R.id.bJugar:
                Intent intent = new Intent(Inicio.this, Niveles.class);//para llamar a una actividad desde otra
                startActivity(intent);
                break;
            case R.id.bSalir:
                if(db != null)
                    db.close();
                finish();
                break;
            case R.id.bHighScores:
                intent = new Intent(Inicio.this, HighScores.class);//para llamar a una actividad desde otra
                startActivity(intent);
                break;
        }/*
        case R.id.sign_out_button:
            if (mPlusClient.isConnected()) {
                mPlusClient.clearDefaultAccount();
                mPlusClient.disconnect();
                mPlusClient.connect();
            }
            break;
        case R.id.revoke_access_button:
            if (mPlusClient.isConnected()) {
                mPlusClient.revokeAccessAndDisconnect(this);
                updateButtons(false  isSignedIn );
            }
            break;
        }*/
    }

    @Override
    protected Dialog onCreateDialog(int id) {
        if (id != DIALOG_GET_GOOGLE_PLAY_SERVICES) {
            return super.onCreateDialog(id);
        }

        int available = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
        if (available == ConnectionResult.SUCCESS) {
            return null;
        }
        if (GooglePlayServicesUtil.isUserRecoverableError(available)) {
            return GooglePlayServicesUtil.getErrorDialog(
                    available, this, REQUEST_CODE_GET_GOOGLE_PLAY_SERVICES);
        }
        return new AlertDialog.Builder(this)
                .setMessage(R.string.plus_generic_error)
                .setCancelable(true)
                .create();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_CODE_SIGN_IN
                || requestCode == REQUEST_CODE_GET_GOOGLE_PLAY_SERVICES) {
            if (resultCode == RESULT_OK && !mPlusClient.isConnected()
                    && !mPlusClient.isConnecting()) {
                // This time, connect should succeed.
                mPlusClient.connect();
            }
        }
    }

    public void onAccessRevoked(ConnectionResult status) {
        if (status.isSuccess()) {
            mSignInStatus.setText(R.string.revoke_access_status);
        } else {
            mSignInStatus.setText(R.string.revoke_access_error_status);
            mPlusClient.disconnect();
        }
        mPlusClient.connect();      
    }

    public void onConnected(Bundle connectionHint) {
        String currentPersonName = mPlusClient.getCurrentPerson() != null
                ? mPlusClient.getCurrentPerson().getDisplayName(): getString(R.string.unknown_person);
        mSignInStatus.setText(getString(R.string.signed_in_status, currentPersonName));
        updateButtons(true /* isSignedIn */);
    }
    /*
    public void onConnected(Bundle connectionHint) {
        mConnectionProgressDialog.dismiss();
        Toast.makeText(this, "User is connected!", Toast.LENGTH_LONG).show();
    }*/

    public void onDisconnected() {
        mSignInStatus.setText(R.string.loading_status);
        mPlusClient.connect();
        updateButtons(false /* isSignedIn */);      
    }

    public void onConnectionFailed(ConnectionResult result) {
        mConnectionResult = result;
        updateButtons(false /* isSignedIn */);
    }

     private void updateButtons(boolean isSignedIn) {
            if (isSignedIn) {
                mSignInButton.setVisibility(View.INVISIBLE);
                mSignOutButton.setEnabled(true);
                mRevokeAccessButton.setEnabled(true);
            } else {
                if (mConnectionResult == null) {
                    // Disable the sign-in button until onConnectionFailed is called with result.
                    mSignInButton.setVisibility(View.INVISIBLE);
                    mSignInStatus.setText(getString(R.string.loading_status));
                } else {
                    // Enable the sign-in button since a connection result is available.
                    mSignInButton.setVisibility(View.VISIBLE);
                    mSignInStatus.setText(getString(R.string.signed_out_status));
                }

                mSignOutButton.setEnabled(false);
                mRevokeAccessButton.setEnabled(false);
            }
        }

LogCat显示

05-21 17:07:43.022: D/ENBUBBLED(24628): Entering connect
05-21 17:07:43.022: W/dalvikvm(24628): VFY: unable to resolve static field 2293 (common_google_play_services_install_title) in Lcom/google/android/gms/R$string;
05-21 17:07:43.032: D/dalvikvm(24628): VFY: replacing opcode 0x60 at 0x004b
05-21 17:07:43.032: W/dalvikvm(24628): VFY: unable to resolve static field 2289 (common_google_play_services_enable_title) in Lcom/google/android/gms/R$string;
05-21 17:07:43.032: D/dalvikvm(24628): VFY: replacing opcode 0x60 at 0x0056
05-21 17:07:43.032: W/dalvikvm(24628): VFY: unable to resolve static field 2304 (common_google_play_services_update_title) in Lcom/google/android/gms/R$string;
05-21 17:07:43.032: D/dalvikvm(24628): VFY: replacing opcode 0x60 at 0x0061
05-21 17:07:43.032: W/dalvikvm(24628): VFY: unable to resolve static field 2301 (common_google_play_services_unsupported_title) in Lcom/google/android/gms/R$string;
05-21 17:07:43.032: D/dalvikvm(24628): VFY: replacing opcode 0x60 at 0x0073
05-21 17:07:43.032: W/dalvikvm(24628): VFY: unable to resolve static field 2297 (common_google_play_services_network_error_title) in Lcom/google/android/gms/R$string;
05-21 17:07:43.032: D/dalvikvm(24628): VFY: replacing opcode 0x60 at 0x0085
05-21 17:07:43.032: W/dalvikvm(24628): VFY: unable to resolve static field 2295 (common_google_play_services_invalid_account_title) in Lcom/google/android/gms/R$string;
05-21 17:07:43.032: D/dalvikvm(24628): VFY: replacing opcode 0x60 at 0x00af
05-21 17:07:43.032: W/dalvikvm(24628): VFY: unable to resolve static field 2301 (common_google_play_services_unsupported_title) in Lcom/google/android/gms/R$string;
05-21 17:07:43.032: D/dalvikvm(24628): VFY: replacing opcode 0x60 at 0x00ce
05-21 17:07:43.032: D/lights(427): LCD : 42 +
05-21 17:07:43.032: D/lights(427): LCD : 42 -
05-21 17:07:43.042: W/dalvikvm(24628): VFY: unable to resolve static field 2290 (common_google_play_services_install_button) in Lcom/google/android/gms/R$string;
05-21 17:07:43.042: D/dalvikvm(24628): VFY: replacing opcode 0x60 at 0x000f
05-21 17:07:43.042: W/dalvikvm(24628): VFY: unable to resolve static field 2287 (common_google_play_services_enable_button) in Lcom/google/android/gms/R$string;
05-21 17:07:43.042: D/dalvikvm(24628): VFY: replacing opcode 0x60 at 0x0016
05-21 17:07:43.042: W/dalvikvm(24628): VFY: unable to resolve static field 2302 (common_google_play_services_update_button) in Lcom/google/android/gms/R$string;
05-21 17:07:43.042: D/dalvikvm(24628): VFY: replacing opcode 0x60 at 0x001d
05-21 17:07:43.042: W/dalvikvm(24628): VFY: unable to resolve static field 2298 (common_google_play_services_unknown_issue) in Lcom/google/android/gms/R$string;
05-21 17:07:43.042: D/dalvikvm(24628): VFY: replacing opcode 0x60 at 0x0007
05-21 17:07:43.042: W/dalvikvm(24628): VFY: unable to resolve static field 2292 (common_google_play_services_install_text_tablet) in Lcom/google/android/gms/R$string;
05-21 17:07:43.042: D/dalvikvm(24628): VFY: replacing opcode 0x60 at 0x0018
05-21 17:07:43.042: W/dalvikvm(24628): VFY: unable to resolve static field 2291 (common_google_play_services_install_text_phone) in Lcom/google/android/gms/R$string;
05-21 17:07:43.042: D/dalvikvm(24628): VFY: replacing opcode 0x60 at 0x0038
05-21 17:07:43.052: W/dalvikvm(24628): VFY: unable to resolve static field 2288 (common_google_play_services_enable_text) in Lcom/google/android/gms/R$string;
05-21 17:07:43.052: D/dalvikvm(24628): VFY: replacing opcode 0x60 at 0x003f
05-21 17:07:43.052: W/dalvikvm(24628): VFY: unable to resolve static field 2303 (common_google_play_services_update_text) in Lcom/google/android/gms/R$string;
05-21 17:07:43.052: D/dalvikvm(24628): VFY: replacing opcode 0x60 at 0x0046
05-21 17:07:43.052: W/dalvikvm(24628): VFY: unable to resolve static field 2300 (common_google_play_services_unsupported_text) in Lcom/google/android/gms/R$string;
05-21 17:07:43.052: D/dalvikvm(24628): VFY: replacing opcode 0x60 at 0x0066
05-21 17:07:43.052: W/dalvikvm(24628): VFY: unable to resolve static field 2296 (common_google_play_services_network_error_text) in Lcom/google/android/gms/R$string;
05-21 17:07:43.052: D/dalvikvm(24628): VFY: replacing opcode 0x60 at 0x006d
05-21 17:07:43.052: W/dalvikvm(24628): VFY: unable to resolve static field 2294 (common_google_play_services_invalid_account_text) in Lcom/google/android/gms/R$string;
05-21 17:07:43.052: D/dalvikvm(24628): VFY: replacing opcode 0x60 at 0x0074
05-21 17:07:43.052: W/dalvikvm(24628): VFY: unable to resolve static field 2299 (common_google_play_services_unsupported_date_text) in Lcom/google/android/gms/R$string;
05-21 17:07:43.052: D/dalvikvm(24628): VFY: replacing opcode 0x60 at 0x007b
05-21 17:07:43.052: D/lights(427): LCD : 43 +
05-21 17:07:43.052: D/lights(427): LCD : 43 -
05-21 17:07:43.052: I/PowerManagerService(427): Light Animator Finished currentValue=43
05-21 17:07:43.062: W/dalvikvm(24628): VFY: unable to resolve static field 2298 (common_google_play_services_unknown_issue) in Lcom/google/android/gms/R$string;
05-21 17:07:43.062: D/dalvikvm(24628): VFY: replacing opcode 0x60 at 0x000c
05-21 17:07:43.092: E/GooglePlayServicesUtil(24628): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
05-21 17:07:43.332: E/ThermalDaemon(997): CPU[1] offline

1 个答案:

答案 0 :(得分:1)

问题的核心在于日志中的这一行:

05-21 17:07:43.092: E/GooglePlayServicesUtil(24628): The Google Play services
                    resources were not found. Check your project configuration
                    to ensure that the resources are included.

(我添加了换行符以便于阅读。)

您似乎没有在自己的应用中加入Google Play服务库。您需要做的事情在this tutorial中进行了描述。