Google + para android (obtener puntero nulo)

Estoy tratando de incorporar Google+ para Android a través de esta documentación oficial de google . Después de seguir los pasos dados:

  1. Descargar el SDK más reciente
  2. Con Android 4.4.2,
  3. Configuró Eclipse para usar Java 1.7 (aunque está diciendo que usa 1.6, supongo que no es mi problema)
  4. A continuación, habilite la API de Google+ proporcionando Package.Name y Sha1 . Luego configuro la aplicación de ejemplo y adjunto google-play-services_lib (importado) a ella.

Ahora, cuando estoy ejecutando la aplicación que está dando la excepción en MainActivity

 mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Plus.API, null) // here the exception (nullPointerException) .addScope(Plus.SCOPE_PLUS_LOGIN).build(); 

Estoy corriendo en dispositivo físico Android 4.1.2.

Pasando por Google, pero no tuve suerte.

LogCat:

05-27 10:23:46.808: D/ActivityThread(11136): setTargetHeapUtilization:0.25 05-27 10:23:46.808: D/ActivityThread(11136): setTargetHeapIdealFree:8388608 05-27 10:23:46.808: D/ActivityThread(11136): setTargetHeapConcurrentStart:2097152 05-27 10:23:47.228: D/AndroidRuntime(11136): Shutting down VM 05-27 10:23:47.228: W/dalvikvm(11136): threadid=1: thread exiting with uncaught exception (group=0x411eb438) 05-27 10:23:47.228: E/AndroidRuntime(11136): FATAL EXCEPTION: main 05-27 10:23:47.228: E/AndroidRuntime(11136): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mygoogleplus/com.example.mygoogleplus.GooglePlusMainActivity}: java.lang.NullPointerException: Null options are not permitted for this Api 05-27 10:23:47.228: E/AndroidRuntime(11136): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2114) 05-27 10:23:47.228: E/AndroidRuntime(11136): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139) 05-27 10:23:47.228: E/AndroidRuntime(11136): at android.app.ActivityThread.access$700(ActivityThread.java:143) 05-27 10:23:47.228: E/AndroidRuntime(11136): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241) 05-27 10:23:47.228: E/AndroidRuntime(11136): at android.os.Handler.dispatchMessage(Handler.java:99) 05-27 10:23:47.228: E/AndroidRuntime(11136): at android.os.Looper.loop(Looper.java:137) 05-27 10:23:47.228: E/AndroidRuntime(11136): at android.app.ActivityThread.main(ActivityThread.java:4960) 05-27 10:23:47.228: E/AndroidRuntime(11136): at java.lang.reflect.Method.invokeNative(Native Method) 05-27 10:23:47.228: E/AndroidRuntime(11136): at java.lang.reflect.Method.invoke(Method.java:511) 05-27 10:23:47.228: E/AndroidRuntime(11136): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038) 05-27 10:23:47.228: E/AndroidRuntime(11136): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805) 05-27 10:23:47.228: E/AndroidRuntime(11136): at dalvik.system.NativeStart.main(Native Method) 05-27 10:23:47.228: E/AndroidRuntime(11136): Caused by: java.lang.NullPointerException: Null options are not permitted for this Api 05-27 10:23:47.228: E/AndroidRuntime(11136): at com.google.android.gms.internal.fq.b(Unknown Source) 05-27 10:23:47.228: E/AndroidRuntime(11136): at com.google.android.gms.common.api.GoogleApiClient$Builder.addApi(Unknown Source) 05-27 10:23:47.228: E/AndroidRuntime(11136): at com.example.mygoogleplus.GooglePlusMainActivity.onCreate(GooglePlusMainActivity.java:89) 05-27 10:23:47.228: E/AndroidRuntime(11136): at android.app.Activity.performCreate(Activity.java:5203) 05-27 10:23:47.228: E/AndroidRuntime(11136): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) 05-27 10:23:47.228: E/AndroidRuntime(11136): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2078)

Lo siguiente ha funcionado para mí.

Simplemente pase un solo parámetro de esta manera.

 .addApi(Plus.API) 

en lugar de

 .addApi(Plus.API, null) 

O

También se puede pasar un objeto PlusOptions

 .addApi(Plus.API, Plus.PlusOptions.builder().build()) 

Cualquiera de estas soluciones funcionará.

Debe crear opciones para esa API

 .addApi(Plus.API, PlusOptions.builder().build()) 

Si utiliza GameHelper – debe llamar a setPlusApiOptions antes de la instalación.

 // Google Play Services m_GameHelper = new GameHelper(this, GameHelper.CLIENT_GAMES | GameHelper.CLIENT_PLUS); m_GameHelper.setPlusApiOptions( PlusOptions.builder().build() ); m_GameHelper.setup(this); 
 mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Plus.API) .addScope(Plus.SCOPE_PLUS_LOGIN) .build(); 

Ha funcionado para mí. MGoogleApiClient es un objeto de GoogleApiClient. Pase Sólo un parámetro en addApi (). Me gusta

 .addApi(Plus.API) 
  • La fuerza de la aplicación se cierra cuando google + no está instalado
  • ¿Cómo Google consigue posts animados en su aplicación de G +?
  • ActivityNotFoundException en Google Plus
  • Integración de Google + en la vista web
  • ¿Cómo integrar Google Plus y Facebook Authentication juntos en la misma actividad del proyecto Android?
  • Nativo de Google Plus Login para Xamarin.Android y Xamarin.iOS
  • Android Google plus personalización de inicio de sesión
  • Integración con Android de Google+ - repetida UserRecoverableAuthException
  • Token de acceso recuperado: null. Com.google.android.gms.auth.GoogleAuthException: Desconocido
  • ¿Cómo comprobar si un usuario ha iniciado sesión en Google+?
  • Android Google Plus SDK: cómo obtener la devolución de llamada en el botón +1 (PlusOneButton)
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.