- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
很长一段时间以来,我一直在努力弄清楚如何解决这个问题,但我找不到任何关于问题所在的好信息。
代码来源于:http://developer.android.com/google/auth/api-client.html
所以我首先构建了 GoogleApiClient 对象,然后 onStart() 尝试连接它。连接失败,我最终进入“onConnectionFailed()”..
我在这里打印了结果,这是我得到的:“SIGN_IN_REQUIRED”
由于该错误有解决方案“result.startResolutionForResult(this, REQUEST_RESOLVE_ERROR)”将被调用。
这里是程序突然崩溃的地方。
如有任何帮助,我将不胜感激 我是 Android 开发的新手,所以请放轻松!
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.util.Log;
import android.view.Menu;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.plus.Plus;
public class MainActivity extends Activity implements
ConnectionCallbacks, OnConnectionFailedListener {
/* Client used to interact with Google APIs. */
private GoogleApiClient mGoogleApiClient;
// Request code to use when launching the resolution activity
private static final int REQUEST_RESOLVE_ERROR = 1001;
// Bool to track whether the app is already resolving an error
private boolean mResolvingError = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
super.onCreate(savedInstanceState);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API, null)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
protected void onStop() {
super.onStop();
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
}
@Override
public void onConnectionFailed(ConnectionResult result) {
if (mResolvingError) {
// Already attempting to resolve an error.
return;
} else if (result.hasResolution()) {
Log.d("MyApp",result.toString());
try {
mResolvingError = true;
result.startResolutionForResult(this, REQUEST_RESOLVE_ERROR);
} catch (SendIntentException e) {
// There was an error with the resolution intent. Try again.
mGoogleApiClient.connect();
}
} else {
// Show dialog using GooglePlayServicesUtil.getErrorDialog()
//showErrorDialog(result.getErrorCode());
mResolvingError = true;
}
}
@Override
public void onConnected(Bundle connectionHint) {
}
@Override
public void onConnectionSuspended(int cause) {
mGoogleApiClient.connect();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_RESOLVE_ERROR) {
mResolvingError = false;
if (resultCode == RESULT_OK) {
// Make sure the app is not already connected or attempting to connect
if (!mGoogleApiClient.isConnecting() && !mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
}
}
}
}
}
最佳答案
在 onCreate
方法中尝试:
super.onCreate(savedInstanceState);
.addScope(Plus.SCOPE_PLUS_LOGIN)
或 .setScopes("PLUS_LOGIN")
就像我的情况一样如果这没有帮助,请尝试从 SDK 样本导入并运行优秀的示例项目:
<android-sdk-folder>/extras/google/google_play_services/
参见 https://developers.google.com/+/mobile/android/getting-started
关于android - startResolutionForResult 返回错误(应用程序崩溃),GoogleApiClient 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21959349/
我正在尝试通过编写 GPS 跟踪服务向我的应用添加 GPS 跟踪功能。我一直在关注有关如何通过 Google Play 服务执行此操作的 Android 开发人员资料,但我一直停留在 onConnec
所以我正在使用一个 gps 类来打开 gps,这是一个允许我们发送到 onActivityResult 的方法。 ,但由于在 AndroidX 上已弃用且仍然可用,android 团队向我们推荐下一个
enter image description here 无论如何都要覆盖 startResolutionForResult() 返回的 google play 服务对话框。我正在从位置设置 api
适用于 Android 的 Google API 允许我显示一个对话框,要求用户打开禁用的设置,如下所示 dialog使用状态类。如何更改对话框的标题? 我无法实现自定义对话框的其他选项,因为我会询问
很长一段时间以来,我一直在努力弄清楚如何解决这个问题,但我找不到任何关于问题所在的好信息。 代码来源于:http://developer.android.com/google/auth/api-cli
我正在尝试将 Google 云端硬盘应用到我的 Android 应用程序,但我什至无法连接到 Api 客户端。我不知道为什么: 我已经在开发者控制台中为 ~/.android/debug.keysto
我看过这个问答 LocationSettingsRequest dialog - onActivityResult() skipped .这不是同一个问题,因为一切都已经在 Activity 中完成了
我正在为 Google Play 制作 Cordova 插件。目前,我已经通过手动修改我的 CordovaActivity 函数“损坏”了该插件。我需要将所有代码放入插件文件中,而不是在 Cordov
当我调用以编程方式使用 GoogleApiClient 将 gps 启用到 fragment 中时出现问题...我的代码是.. final Status status = result.getSta
a据此: https://developers.google.com/android/reference/com/google/android/gms/location/SettingsApi 您可以
我正在使用 Google 登录 Authenticate with a backend server ,并想测试我是否在使用 Status#hasResolution和 Status#startRes
我是一名优秀的程序员,十分优秀!