无法连接到AVD上的GooglePlayServices [英] Trouble connecting to GooglePlayServices on AVD

查看:162
本文介绍了无法连接到AVD上的GooglePlayServices的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试访问GooglePlayServices。 AVD(API 23)上所有其他功能的互联网工作正常,但我不太清楚我的实际应用程序出现了什么问题。



每次尝试连接,它说连接失败。我相信我已经正确设置了GoogleAPIClient,但在ConnectionRequest中,我没有定制任何设置(为简单起见)。



这是我的一些应用程序代码来提供一些信息。

Manifest.xml

 < ?xml version =1.0encoding =utf-8?> 

 < uses-permission android:name =android.permission.ACCESS_FINE_LOCATION/> 
< uses-permission android:name =android.permission.INTERNET/>

< application
android:name =.Protoype2
android:allowBackup =true
android:label =@ string / app_name
android:supportsRtl =true
android:theme =@ style / AppTheme>
< activity
android:name =。MainActivity
android:label =@ string / app_name
android:theme =@ style / AppTheme.NoActionBar> ;
< intent-filter>

< category android:name =android.intent.category.LAUNCHER/>
< / intent-filter>
< / activity>
android:name =。SettingsMenu
android:label =@ string / title_activity_settings_menu
android:parentActivityName =。MainActivity
android :主题= @风格/ AppTheme.NoActionBar >
< meta-data
android:name =android.support.PARENT_ACTIVITY
android:value =com.example.denny.protoype2.MainActivity/>
< / activity>
< activity
android:name =。ViewingWindow
android:label =@ string / title_activity_viewing_window
android:parentActivityName =。MainActivity
android :主题= @风格/ AppTheme.NoActionBar >
< meta-data
android:name =android.support.PARENT_ACTIVITY
android:value =com.example.denny.protoype2.MainActivity/>
< / activity>
< / application>



onCreate();从相关的类

  protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_viewing_window);
mRequestingLocationUpdates =((Protoype2)getApplication())。getRequestingLocationUpdates();
if(!mRequestingLocationUpdates){
StoppedMessage();
}
ExceedInstance = 0;
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this,this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
。建立();
String [] LocationPermission = new String [] {Manifest.permission.ACCESS_FINE_LOCATION};
if(ActivityCompat.shouldShowRequestPermissionRationale(ViewingWindow.this,
Manifest.permission.ACCESS_FINE_LOCATION)
if(ContextCompat.checkSelfPermission )){
GPSExplanation();
} else {
ActivityCompat.requestPermissions(ViewingWindow.this,
new String [] {Manifest.permission.ACCESS_FINE_LOCATION},
MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
}

}
onRequestPermissionsResult(MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION,LocationPermission,grantResults);

最终Button BackButton =(Button)findViewById(R.id.VWBackButton);
BackButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Intent GoBackIntent = new Intent(ViewingWindow.this,MainActivity.class);
startActivity(GoBackIntent);
}
});
updateValuesFromBundle(savedInstanceState);






最后,几种预定义的连接方法:

 保护无效onStart(){
super.onStart();
mGoogleApiClient.connect();
}

public void onConnected(Bundle connectionHint){
createLocationRequest();
if(mRequestingLocationUpdates){
startLocationUpdates();



protected LocationRequest createLocationRequest(){
return new LocationRequest();


解决方案

检查您的AVD是否有适当版本的Google Play服务APK,实施 onConnectionFailed() 回调方法。使用参数 ConnectionResult ,可用于解决错误,并确定发生了什么样的错误。


要解决该错误,解决方案必须从传递给非负的 requestCode 的活动启动 startResolutionForResult( Activity,int) 。应用程序应在其Activity中实现onActivityResult以调用 RESULT_OK )。


基于此文档,当您的应用收到对 onConnectionFailed() )回调时,应该调用< a href =https:// develo pers.google.com/android/reference/com/google/android/gms/common/ConnectionResult#public-methodsrel =nofollow noreferrer> hasResolution() 上的 ConnectionResult 对象。如果它返回true,则您的应用可以通过调用 startResolutionForResult() 关于 ConnectionResult object。



请查看相关的问题。希望能帮助到你!

I am currently trying to access the GooglePlayServices. The internet for all the other functions on the AVD (API 23) works fine, however I am not quite sure what the problem is on my actual app.

Everytime I try to connect, it says that Connection has failed. I believe I have set up the GoogleAPIClient correctly, though in the ConnectionRequest, I have not customised any of the settings (for simplicity's sake).

This is some of my app's code to provide some information.

Manifest.xml

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:name=".Protoype2"
    android:allowBackup="true"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".SettingsMenu"
        android:label="@string/title_activity_settings_menu"
        android:parentActivityName=".MainActivity"
        android:theme="@style/AppTheme.NoActionBar">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.denny.protoype2.MainActivity" />
    </activity>
    <activity
        android:name=".ViewingWindow"
        android:label="@string/title_activity_viewing_window"
        android:parentActivityName=".MainActivity"
        android:theme="@style/AppTheme.NoActionBar">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.denny.protoype2.MainActivity" />
    </activity>
</application>

onCreate(); from the relevant Class

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_viewing_window);
    mRequestingLocationUpdates = ((Protoype2)getApplication()).getRequestingLocationUpdates();
    if (!mRequestingLocationUpdates) {
        StoppedMessage();
    }
    ExceedInstance = 0;
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, this)
            .addApi(Drive.API)
            .addScope(Drive.SCOPE_FILE)
            .build();
    String[] LocationPermission = new String[]{Manifest.permission.ACCESS_FINE_LOCATION};
    if (ContextCompat.checkSelfPermission(ViewingWindow.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        if (ActivityCompat.shouldShowRequestPermissionRationale(ViewingWindow.this,
                Manifest.permission.ACCESS_FINE_LOCATION)) {
            GPSExplanation();
        } else {
            ActivityCompat.requestPermissions(ViewingWindow.this,
                    new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                    MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
        }

    }
    onRequestPermissionsResult(MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION, LocationPermission, grantResults);

    final Button BackButton = (Button)findViewById(R.id.VWBackButton);
    BackButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent GoBackIntent = new Intent (ViewingWindow.this, MainActivity.class);
            startActivity(GoBackIntent);
        }
    });
    updateValuesFromBundle(savedInstanceState);

}

Finally, the several predefined methods of connection:

protected void onStart() {
    super.onStart();
    mGoogleApiClient.connect();
}

public void onConnected(Bundle connectionHint) {
    createLocationRequest();
    if (mRequestingLocationUpdates) {
        startLocationUpdates();
    }
}

protected LocationRequest createLocationRequest() {
    return new LocationRequest();
}

解决方案

Check if your AVD has the appropriate version of the Google Play services APK, implement the onConnectionFailed() callback method. Use the parameter ConnectionResult that can be used for resolving the error, and deciding what sort of error occurred.

To resolve the error, the resolution must be started from an activity with a non-negative requestCode passed to startResolutionForResult(Activity, int). Applications should implement onActivityResult in their Activity to call connect() again if the user has resolved the issue (resultCode is RESULT_OK).

Based from this documentation, when your app receives a call to the onConnectionFailed()) callback, you should call hasResolution() on the provided ConnectionResult object. If it returns true, your app can request that the user take immediate action to resolve the error by calling startResolutionForResult() on the ConnectionResult object.

Check this related question. Hope it helps!

这篇关于无法连接到AVD上的GooglePlayServices的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆