使用 google + 登录后,它会询问我是想要公开还是只想查看它。我说公开或另一个,它让我登录。然后我在谷歌检查我允许的应用程序,它显示我在谷歌上的应用程序,所以我连接了。
但是在连接我的整个应用程序后冻结,因为在工作日志中它告诉我定位帐户的问题。我不知道为什么这种情况不断发生,我无法找出原因。为了修复它,我必须登录谷歌并将我的应用程序与谷歌允许的应用程序列表断开连接,而不是我的应用程序。这是代码
它不是我的应用程序的完整代码,但它是我使用的完整谷歌登录代码
Java 代码
public class mainMenu extends Activity implements ConnectionCallbacks, OnConnectionFailedListener, OnClickListener {
private static final int REQUEST_CODE_RESOLVE_ERR = 9000;
private ProgressDialog mConnectionProgressDialog;
private PlusClient mPlusClient;
private ConnectionResult mConnectionResult;
private static final String TAG = "Back To School";
static final String[] SCOPES = new String[] {Scopes.PLUS_PROFILE};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); //This is calling the layout in the main.xml file if I change the main.xml file name then I would
mPlusClient = new PlusClient.Builder(this, this, this)
.setVisibleActivities("http://schemas.google.com/AddActivity", "http://schemas.google.com/BuyActivity").build();
// Progress bar to be displayed if the connection failure is not resolved.
mConnectionProgressDialog = new ProgressDialog(this);
mConnectionProgressDialog.setMessage("Signing in...");
findViewById(R.id.sign_in_google).setOnClickListener(this);
@Override
protected void onStart() {
super.onStart();
mPlusClient.connect();
}
@Override
protected void onStop() {
super.onStop();
mPlusClient.disconnect();
}
public void onConnectionFailed(ConnectionResult result) {
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 (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(Bundle connectionHint) {
String accountName = mPlusClient.getAccountName();
Toast.makeText(this, accountName + " is connected.", Toast.LENGTH_LONG).show();
}
public void onDisconnected() {
Log.d(TAG, "disconnected");
}
XML 代码
<com.google.android.gms.common.SignInButton
android:id="@+id/sign_in_google"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
任何人都知道为什么它在登录并允许它进入我的谷歌登录后冻结。
顺便说一句,我已经做了下面的客户端 ID 部分,但我无法弄清楚范围是什么,所以现在将其注释掉
暂时未使用 Java 代码
// Prior to disconnecting, run clearDefaultAccount().
/*
mPlusClient.clearDefaultAccount();
mPlusClient.revokeAccessAndDisconnect(new OnAccessRevokedListener() {
public void onAccessRevoked(ConnectionResult status) {
// mPlusClient is now disconnected and access has been revoked.
// Trigger app logic to comply with the developer policies
}
});
Bundle appActivities = new Bundle();
appActivities.putString(GoogleAuthUtil.KEY_REQUEST_VISIBLE_ACTIVITIES,
"<app-activity1> <app-activity2>");
String scopes = "oauth2:server:client_id:44890425655.apps.googleusercontent.com:api_scope:<scope1> <scope2>";
@SuppressWarnings("unused")
String code = null;
try {
code = GoogleAuthUtil.getToken(
this, // Context context
mPlusClient.getAccountName(), // String accountName
scopes, // String scope
appActivities // Bundle bundle
);
} catch (IOException transientEx) {
// network or server error, the call is expected to succeed if you try again later.
// Don't attempt to call again immediately - the request is likely to
// fail, you'll hit quotas or back-off.
return;
} catch (UserRecoverableAuthException e) {
// Recover
code = null;
} catch (GoogleAuthException authEx) {
// Failure. The call is not expected to ever succeed so it should not be
// retried.
return;
} catch (Exception e) {
throw new RuntimeException(e);
}*/
这是原木猫
08-13 22:45:48.970: E/AndroidRuntime(19298): java.lang.SecurityException: Missing android.permission.GET_ACCOUNTS
08-13 22:45:48.970: E/AndroidRuntime(19298): at android.os.Parcel.readException(Parcel.java:1425)
08-13 22:45:48.970: E/AndroidRuntime(19298): at android.os.Parcel.readException(Parcel.java:1379)
08-13 22:45:48.970: E/AndroidRuntime(19298): at com.google.android.gms.internal.dx$a$a.getAccountName(Unknown Source)
08-13 22:45:48.970: E/AndroidRuntime(19298): at com.google.android.gms.internal.dy.getAccountName(Unknown Source)
08-13 22:45:48.970: E/AndroidRuntime(19298): at com.google.android.gms.plus.PlusClient.getAccountName(Unknown Source)
08-13 22:45:48.970: E/AndroidRuntime(19298): at com.better.work.learning.letters.and.more.awesome.mainMenu.onConnected(mainMenu.java:218)
08-13 22:45:48.970: E/AndroidRuntime(19298): at com.google.android.gms.internal.p.k(Unknown Source)
08-13 22:45:48.970: E/AndroidRuntime(19298): at com.google.android.gms.internal.p$f.a(Unknown Source)
08-13 22:45:48.970: E/AndroidRuntime(19298): at com.google.android.gms.internal.p$f.a(Unknown Source)
08-13 22:45:48.970: E/AndroidRuntime(19298): at com.google.android.gms.internal.p$b.p(Unknown Source)
08-13 22:45:48.970: E/AndroidRuntime(19298): at com.google.android.gms.internal.p$a.handleMessage(Unknown Source)
08-13 22:45:48.970: E/AndroidRuntime(19298): at android.os.Handler.dispatchMessage(Handler.java:99)
08-13 22:45:48.970: E/AndroidRuntime(19298): at android.os.Looper.loop(Looper.java:137)
08-13 22:45:48.970: E/AndroidRuntime(19298): at android.app.ActivityThread.main(ActivityThread.java:4898)
08-13 22:45:48.970: E/AndroidRuntime(19298): at java.lang.reflect.Method.invokeNative(Native Method)
08-13 22:45:48.970: E/AndroidRuntime(19298): at java.lang.reflect.Method.invoke(Method.java:511)
08-13 22:45:48.970: E/AndroidRuntime(19298): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
08-13 22:45:48.970: E/AndroidRuntime(19298): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
08-13 22:45:48.970: E/AndroidRuntime(19298): at dalvik.system.NativeStart.main(Native Method)