我已经使用下面的代码来打开gps,比如OLA应用。以下代码在Android Studio中使用播放服务8.4.0成功运行。 但是,我想在Eclipse中使用ADT 23运行此操作。Android需要导入aar play服务8.4.0到eclipse
我已经在sdk中搜索了最新的google playservices。它不可用。然后,最后,我发现最新的aar8.4.0文件。在我已经将AAR转换为正常的Eclipse库项目并导入到Eclipse并刷新并添加为我的主项目库之后。
我仍然得到这个错误。以下API在主要源代码活动中不受支持。
import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; import com.google.android.gms.location.LocationRequest;
我的代码:
@覆盖 公共无效的onCreate(捆绑savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); settingsrequest(); } // --------------------------------------------- ---------------------------------------
public void settingsrequest()
{
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(30 * 1000);
locationRequest.setFastestInterval(5 * 1000);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(locationRequest);
builder.setAlwaysShow(true); //this is the key ingredient
PendingResult<LocationSettingsResult> result =
LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
@Override
public void onResult(LocationSettingsResult result) {
final Status status = result.getStatus();
final LocationSettingsStates state = result.getLocationSettingsStates();
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
// All location settings are satisfied. The client can initialize location
// requests here.
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
// Location settings are not satisfied. But could be fixed by showing the user
// a dialog.
try {
// Show the dialog by calling startResolutionForResult(),
// and check the result in onActivityResult().
status.startResolutionForResult(this, REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException e) {
// Ignore the error.
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
// Location settings are not satisfied. However, we have no way to fix the
// settings so we won't show the dialog.
break;
}
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
// Check for the integer request code originally supplied to startResolutionForResult().
case REQUEST_CHECK_SETTINGS:
switch (resultCode) {
case Activity.RESULT_OK:
//startLocationUpdates();
GetLocation() ;
break;
case Activity.RESULT_CANCELED:
settingsrequest();//keep asking if imp or do whatever
break;
}
break;
}
}
// - -------------------------------------------------- -----------------
注意:此代码完美适用于Android Studio 2.1。并看到输出像直接打开全球定位系统与对话框是/否本身,没有去设置页面。
但是,我想要在Eclipse中相同的输出。我也发现问题在哪里? 问题仅适用于Google Play服务。现在Google API仅为AAR格式提供库(工作室可接受)。
请帮忙解决。
我有转换AAR进行到Android库项目下面的步骤,并在我的主要源代码添加库项目。但是,它的展示成功添加了。但是,google play-services API不能导入。还是一样的错误。 – harikrishnan
如果可能的话,你可以把最新的arr play services8.4.0作为一个库项目导入到eclipse格式。或者如果你想要我的源代码库的手段,我会上传并给你链接。如果可能的话请检查并恢复我,我犯了什么错误。 – harikrishnan
尝试做到这一点有谷歌解释在这里:https://developers.google.com/android/guides/setup Eclipse与ADT部分 –