使用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);
}*/
以下是Log Cat
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)
答案 0 :(得分:0)
我提到了这个链接Android Permissions
我能够解决自己的问题,因为我从未进入清单并在此处添加此行
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
添加此行可以阻止应用程序崩溃,因为它能够找到帐户并存储它们,然后继续连接而没有该行它将无法获得帐户,并且在代码的第一部分将失败获取帐户代码因此导致您的应用程序崩溃。