gpt4 book ai didi

android - 在使用 Google Play 服务时遇到问题 - 使用 GoogleApiClient 时,它总是会触发 onConnectionFailed

转载 作者:IT老高 更新时间:2023-10-28 23:32:52 26 4
gpt4 key购买 nike

目前,我的应用正在使用

  • minSdkVersion 14
  • targetSdkVersion 23
  • 编译'com.google.android.gms:play-services-gcm:8.4.0'
  • 编译'com.google.android.gms:play-services-base:8.4.0'
  • 编译'com.google.android.gms:play-services-analytics:8.4.0'
  • 编译'com.google.android.gms:play-services-ads:8.4.0'
  • 编译'com.google.android.gms:play-services-drive:8.4.0'

我正在使用以下代码执行 GoogleApiClient 连接。

public class GoogleApiClientFragment extends Fragment implements
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

public interface ConnectionCallbacks {
void onConnected(GoogleApiClient googleApiClient, int action);
void onCancel(int action);
}

public static GoogleApiClientFragment newInstance(String accountName, int action) {
GoogleApiClientFragment googleApiClientFragment = new GoogleApiClientFragment();
Bundle bundle = new Bundle();
bundle.putString(INTENT_EXTRA_ACCOUNT_NAME, accountName);
bundle.putInt(INTENT_EXTRA_ACTION, action);
googleApiClientFragment.setArguments(bundle);
return googleApiClientFragment;
}

/**
* Handles resolution callbacks.
*/
@Override
public void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == RequestCode.REQUEST_GOOGLE_API_CLIENT_CONNECT) {
if (resultCode == Activity.RESULT_OK) {
mGoogleApiClient.connect();
} else {
Activity activity = this.getActivity();
if (activity instanceof ConnectionCallbacks) {
ConnectionCallbacks connectionCallbacks = (ConnectionCallbacks)activity;
connectionCallbacks.onCancel(action);
}
}
}
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);

Bundle bundle = this.getArguments();
this.accountName = bundle.getString(INTENT_EXTRA_ACCOUNT_NAME);
this.action = bundle.getInt(INTENT_EXTRA_ACTION);
}

@Override
public void onResume() {
super.onResume();
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this.getContext())
.setAccountName(accountName)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addScope(Drive.SCOPE_APPFOLDER)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();

mGoogleApiClient.connect();
}
}

@Override
public void onConnected(Bundle bundle) {
Log.i(TAG, "GoogleApiClient connected");

Activity activity = this.getActivity();
if (activity instanceof ConnectionCallbacks) {
ConnectionCallbacks connectionCallbacks = (ConnectionCallbacks)activity;
connectionCallbacks.onConnected(mGoogleApiClient, action);
}
}

@Override
public void onConnectionSuspended(int i) {
Log.i(TAG, "GoogleApiClient connection suspended");
}

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.i(TAG, "GoogleApiClient connection failed: " + connectionResult.toString());

if (!connectionResult.hasResolution()) {
Utils.showLongToast("debug two " + connectionResult.toString());

// show the localized error dialog.
GoogleApiAvailability.getInstance().getErrorDialog(this.getActivity(), connectionResult.getErrorCode(), 0).show();
return;
}
try {
connectionResult.startResolutionForResult(this.getActivity(), RequestCode.REQUEST_GOOGLE_API_CLIENT_CONNECT);
} catch (IntentSender.SendIntentException e) {
Log.e(TAG, "Exception while starting resolution activity", e);
}
}

private String accountName = null;
private int action = -1;
private GoogleApiClient mGoogleApiClient;

public static final int ACTION_LOAD_FROM_CLOUD = 0;
public static final int ACTION_SAVE_TO_CLOUD = 1;
private static final String INTENT_EXTRA_ACCOUNT_NAME = "INTENT_EXTRA_ACCOUNT_NAME";
private static final String INTENT_EXTRA_ACTION = "INTENT_EXTRA_ACTION";

private static final String TAG = "GoogleApiClientFragment";
}

某些用户(并非所有用户)遇到以下问题。

is having trouble with Google Play services. If the problem persists, please contact the developer for assistance.

enter image description here

错误对话框是由于 onConnectionFailed 中的 GoogleApiAvailability.getInstance().getErrorDialog 代码造成的。

无论何时

        mGoogleApiClient = new GoogleApiClient.Builder(this.getContext())
.setAccountName(accountName)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addScope(Drive.SCOPE_APPFOLDER)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();

被执行,它总是命中

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {

当我使用 toString 打印出 connectionResult 时,它给出了

ConnectionResult{statusCode=INTERNAL_ERROR, resolution=null, message=null}

我的一个用户具有以下规范。

  • 索尼 Xperia z5
  • Android 6
  • Google Play 服务 9.0.83
  • 他的设备中只有 1 个 Google 帐户

我什至尝试使用 Google Play Services 9.0.1 重新编译 APK。但是,同样的问题仍然存在。

关于如何解决问题的任何想法?

最佳答案

鉴于它正在其他 Anrdoid 6.0 设备上运行,并且您已指定要投诉的设备。我怀疑,这不是你的应用程序。 Sony Xperia z5 在更新到 Android 6.0 时存在一个已知问题。

索尼声称已经修复了这个错误。

Re: "Google Play Store has Stopped" after Z5 Premium Marshmallow Update
April

Hi everyone, I got information today that this will be fixed in the next software update planned to be released soon.
Official Sony Xperia Support Staff

因此,请务必建议客户确保所有索尼更新都是最新的,但这仍然不适用于所有消费者。 坏消息是,除了恢复出厂设置之外没有任何解决办法,所以回到 Android 5 有时会失败。

我建议指导客户与索尼讨论这个问题,如果恢复出厂设置不能解决问题,这将是消费者是否应该更换手机的问题。

索尼移动网站上的这个帖子"Google Play Store has Stopped" after Z5 Premium Marshmallow Update详细讨论了这些问题(上面有 122 条消息),除了恢复出厂设置之外,还有很多建议,例如使用 Sony PC 伴侣。

Xperia Z5 Issues After Android Marshmallow Update: Here's A Fix From Sony

Sony Xperia Z5 users' excitement over receiving the Android 6.0Marshmallow update seems to have been short-lived as users of thehandsets are now complaining of issues after updating the device tothe latest OS.

Users of the smartphone have taken to the Japanese company's onlinesupport page to vent their ire and complain that access to the GooglePlay Store had halted after updating to Android 6.0 Marshmallow.

Several Xperia Z5 users complained that their smartphones "broke"after installing the new OS. They were also greeted by a pop-up signthat says their "Google Play Store has stopped." The users were alsounable to open the Play Store app.

"As soon as I updated to Marshmallow, I keep getting the"Unfortunately Google Play Store has stopped..." and the message keepscoming up every 5 seconds. I tried clearing the cache, deleting data,uninstalling, disabling the app, force closing, signing out of googleand back on. Does not work. I keep getting the pop up non-stop and ithappened as SOON as it updated to Marshmallow," noted a user on thesupport forum.

"Yup, having the same problem here. Tried uninstallingthe updates in /settings/apps/google play store, also tried installingthe .apk through chrome. Still getting the error message. Spoke withcustomer support and running the "repair" option from Sony Bridge wasthe only advice they offered. Creating a back-up now before I tryrunning it..." said another.

Sony has acknowledged the problem and has only offered a factoryreset.

While this resolves the issue for other Xperia Z5 users, some arestill unable to access the Play Store despite performing the reset.

如果这发生在其他设备上,请告诉我,因为此时,我建议这是问题所在,无需更多区分细节。

我已经从高到低进行了搜索,鉴于它适用于大多数设备而不是少数设备,因此很难理解问题所在。我建议使用更新的依赖项运行它,因为 android 6.0 手机使用 Google Play Services 9.0.83,我知道你已经运行了这个,但最好跟上这个。

dependencies {
compile 'com.google.android.gms:play-services:9.0.2'
}

鉴于 Google 服务存在已知错误,Android 6.0 更新以及 Android 5.0 与 5.0.1 和 5.0.2 更新之间存在许多错误。 5.1 中修复了更多问题,但确实很难解决某些问题。

我也遇到过一个应用程序的问题,人们说某某设备无法正常工作,然后尝试对其进行故障排除,因为有时用户手机设置中可能存在问题,这些问题也可能导致应用程序和其中一些设置因手机而异。

我建议在您的 Builder 中显式创建您的监听器,并添加更多日志记录以检查它在失败连接中的确切位置,因为您可以在失败连接中建立连接并需要在其中管理您的连接连接回调。

mGoogleApiClient = new GoogleApiClient.Builder(this.getContext())
.setAccountName(accountName)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addScope(Drive.SCOPE_APPFOLDER)
.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(Bundle bundle) {

if(mGoogleApiClient != null) {
Log.i(TAG, "GoogleApiClient connected");

Activity activity = this.getActivity();
if (activity instanceof ConnectionCallbacks) {
ConnectionCallbacks connectionCallbacks = (ConnectionCallbacks)activity;
connectionCallbacks.onConnected(mGoogleApiClient, action);
}
}
}

@Override
public void onConnectionSuspended(int i) {
mGoogleApiClient.connect();
}
})
.addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.i(TAG, "GoogleApiClient connection failed: " + connectionResult.toString());

if (!connectionResult.hasResolution()) {
Utils.showLongToast("debug two " + connectionResult.toString());

// show the localized error dialog.
GoogleApiAvailability.getInstance().getErrorDialog(this.getActivity(), connectionResult.getErrorCode(), 0).show();
return;
}
try {
connectionResult.startResolutionForResult(this.getActivity(), RequestCode.REQUEST_GOOGLE_API_CLIENT_CONNECT);
} catch (IntentSender.SendIntentException e) {
Log.e(TAG, "Exception while starting resolution activity", e);
}
})
.build();

mGoogleApiClient.connect();
}

我还会添加您的类(class)成员/变量:

private String accountName = null;
private int action = -1;
private GoogleApiClient mGoogleApiClient;
// etc

放在类(class)的顶部,因为将它们放在底部会令人困惑,最好有可读的代码。

这个问题Multiple GoogleApiClient not firing connect()也可能有帮助。

其他人登陆这里的完整性问题:

还需要在某个时候更新到 Firebase Migrate a GCM Client App for Android to Firebase Cloud Messaging .

来自 Release Notes May 2016 - v.9.0

Google Cloud MessagingGoogle Cloud Messaging (GCM) is integrated with Firebase. Existing users of GCM can continue to use GCM without interruption, though we strongly recommend upgrading to the new and simplified Firebase Cloud Messaging (FCM) APIs, so that users can benefit from future releases of new features and enhancements. To learn more, see Migrate a GCM Client App for Android to Firebase Cloud Messaging.

关于android - <Your App> 在使用 Google Play 服务时遇到问题 - 使用 GoogleApiClient 时,它总是会触发 onConnectionFailed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37476432/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com