2013-05-12 13 views
8

Ich verwende com.actionbarsherlock.app.SherlockActivity in meinem Projekt. Wenn ich versuche, eine andere Aktivität zu starten, bei der ich ein Google+ anmelden muss, tritt dieser Fehler auf. Ich erhalte diesen Fehler auf einem tatsächlichen Gerät, nicht auf dem Emulator. Was denkst du, was ich falsch mache?Google + Anmelden: Aktivität wird nicht gestartet

Fehler

05-12 15:58:12.487: E/AndroidRuntime(24310): FATAL EXCEPTION: main 
05-12 15:58:12.487: E/AndroidRuntime(24310): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.android.gms/com.google.android.gms.plus.activity.AccountSignUpActivity}: java.lang.SecurityException: Must be started via startActivityForResult 
05-12 15:58:12.487: E/AndroidRuntime(24310): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 
05-12 15:58:12.487: E/AndroidRuntime(24310): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 
05-12 15:58:12.487: E/AndroidRuntime(24310): at android.app.ActivityThread.access$600(ActivityThread.java:141) 
05-12 15:58:12.487: E/AndroidRuntime(24310): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
05-12 15:58:12.487: E/AndroidRuntime(24310): at android.os.Handler.dispatchMessage(Handler.java:99) 
05-12 15:58:12.487: E/AndroidRuntime(24310): at android.os.Looper.loop(Looper.java:137) 
05-12 15:58:12.487: E/AndroidRuntime(24310): at android.app.ActivityThread.main(ActivityThread.java:5041) 
05-12 15:58:12.487: E/AndroidRuntime(24310): at java.lang.reflect.Method.invokeNative(Native Method) 
05-12 15:58:12.487: E/AndroidRuntime(24310): at java.lang.reflect.Method.invoke(Method.java:511) 
05-12 15:58:12.487: E/AndroidRuntime(24310): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
05-12 15:58:12.487: E/AndroidRuntime(24310): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
05-12 15:58:12.487: E/AndroidRuntime(24310): at dalvik.system.NativeStart.main(Native Method) 
05-12 15:58:12.487: E/AndroidRuntime(24310): Caused by: java.lang.SecurityException: Must be started via startActivityForResult 
05-12 15:58:12.487: E/AndroidRuntime(24310): at com.google.android.gms.plus.activity.AccountSignUpActivity.onCreate(AccountSignUpActivity.java:119) 
05-12 15:58:12.487: E/AndroidRuntime(24310): at android.app.Activity.performCreate(Activity.java:5104) 
05-12 15:58:12.487: E/AndroidRuntime(24310): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 
05-12 15:58:12.487: E/AndroidRuntime(24310): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 
05-12 15:58:12.487: E/AndroidRuntime(24310): ... 11 more 

LandingActivity.java

public class LandingActivity extends SherlockActivity { 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    Intent i = new Intent(getApplicationContext(), SignInActivity.class); 
    this.startActivityForResult(i, 1); 
} 
} 

SignInActivity.java

import com.actionbarsherlock.app.SherlockActivity; 
import android.view.View; 
import android.app.ProgressDialog; 
import android.content.Intent; 
import android.content.IntentSender.SendIntentException; 
import android.os.Bundle; 
import android.util.Log; 
import android.widget.Toast; 
//import com.google.android.gms.common.*; 
//import com.google.android.gms.common.GooglePlayServicesClient.*; 
import com.google.android.gms.common.ConnectionResult; 
import com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks; 
import com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener; 
import com.google.android.gms.plus.PlusClient; 


/** 
* Example of signing in a user with Google+, and how to make a call to a Google+ API endpoint. 
*/ 
public class SignInActivity extends SherlockActivity 
implements View.OnClickListener, ConnectionCallbacks, OnConnectionFailedListener 
{ 
    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 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.sign_in_activity); 
     findViewById(R.id.sign_in_button_dude).setOnClickListener(this); 

     mPlusClient = new PlusClient.Builder(this, this, this).build(); 
     //.setVisibleActivities("http://schemas.google.com/AddActivity", "http://schemas.google.com/BuyActivity") 
     // Progress bar to be displayed if the connection failure is not resolved. 
     mConnectionProgressDialog = new ProgressDialog(this); 
     mConnectionProgressDialog.setMessage("Signing in..."); 
    } 

    @Override 
    protected void onStart() { 
     super.onStart(); 
     mPlusClient.connect(); 
    } 

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

    public void onConnectionFailed(ConnectionResult result) { 
     if (result.hasResolution()) { 
      try { 
       result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR); 
      } catch (SendIntentException e) { 
       mPlusClient.connect(); 
      } 
     } 
     // Save the result and resolve the connection failure upon a user click. 
     mConnectionResult = result; 
    } 

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

    public void onConnected() { 
     String accountName = mPlusClient.getAccountName(); 
     //mConnectionProgressDialog.dismiss(); //https://developers.google.com/+/mobile/android/sign-in 
     Toast.makeText(this, accountName + " is connected.", Toast.LENGTH_LONG).show(); 
     //Toast.makeText(this, "User is connected!", Toast.LENGTH_LONG).show(); 
    } 

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

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

I habe auch versucht "setScopes (Scopes.PLUS_LOGIN)" zu benutzen, bin aber auf dasselbe Problem gestoßen.

import com.google.android.gms.common.Scopes; 
// in onCreate() 
mPlusClient = new PlusClient.Builder(this, this, this).setScopes(Scopes.PLUS_LOGIN).build(); 

Ich habe versucht, keytool auch zu starten .... ist androiddebugkey erforderlich? https://developers.google.com/+/mobile/android/getting-started

C:\repos>c:\java\jdk1.6.0_34\bin\keytool.exe -exportcert -alias androiddebugkey -keystore agoyal-release-key.keystore -list -v 
Enter keystore password: 
keytool error: java.lang.Exception: Alias <androiddebugkey> does not exist 
    java.lang.Exception: Alias <androiddebugkey> does not exist 
    at sun.security.tools.KeyTool.doPrintEntry(KeyTool.java:1339) 
    at sun.security.tools.KeyTool.doCommands(KeyTool.java:869) 
    at sun.security.tools.KeyTool.run(KeyTool.java:172) 
    at sun.security.tools.KeyTool.main(KeyTool.java:166) 
+1

** "Was mache ich falsch?" ** Nun, das erste, was Sie falsch machen, ist, dass Sie uns nicht alle Ihren Code zeigen. Das Problem liegt bei 'com.google.android.gms.plus.activity.AccountSignUpActivity'. Angenommen, Sie versuchen, dies von Ihrer 'SignInActivity' aus zu starten, hilft es nicht, dass Sie nur'/* code */'dafür angezeigt haben. – Squonk

+0

Squonk: Ich habe den ganzen Code in SignInActivity.java – AG1

+0

geteilt Von der Logcat, stimme ich @Squonk, gibt es einige Code fehlt! – thiagolr

Antwort

1

für den Befehl keytool, wenn Sie Ihren eigenen Freigabeschlüssel verwenden, sollte der Alias ​​das nicht „androiddebugkey“ verwendet, um einer Ihres Schlüssel sein.

+0

danke dafür - ich weiß nicht, warum Google das in ihren Dokumenten nicht klarstellt ... – bkurzius

0

Etwas stimmt nicht, sind Sie sicher, dass die richtige Logcat-Ausgabe war?

Mit Ihrem Code sollten Sie die android.app.SuperNotCalledException: Activity {LandingActivity} did not call through to super.onCreate() Ausnahme anstelle des Fehlers erhalten, die Sie zeigen.

Auch Ihre public onConnected() Methode in der SignInActivity hat eine falsche Signatur. Der richtige sollte public onConnected(Bundle connectionHint) sein. Es ist wahrscheinlich, dass deine App nicht korrekt kompiliert wurde.

Verwandte Themen