gpt4 book ai didi

android - 如果我的应用程序针对牛轧糖设备,startService() 是否仍然有效

转载 作者:搜寻专家 更新时间:2023-11-01 09:26:04 29 4
gpt4 key购买 nike

这就是我启动位置服务的方式。

private void initLocationService() {

locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

if(getPermissions(android.Manifest.permission.ACCESS_FINE_LOCATION,GET_LOCATION_PERMISSION)){
startService(new Intent(HomeActivity.this, LocationUpdateService.class));
}
}

LocationUpdateService 中,我将其作为 STICKY 服务启动。所以它一直在后台工作。

public class LocationUpdateService extends Service implements
LocationListener,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
IServiceResponse {


@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG, "onStartCommand: ");
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(BACKGROUND_INTERVAL);
mLocationRequest.setFastestInterval(BACKGROUND_INTERVAL);
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);

super.onStartCommand(intent, flags, startId);
return START_STICKY;
}

由于我的应用当前针对 Api 25 (Nougat),我需要对此特定服务进行哪些更改才能使其在 Oreo

在使用 compileSdkVersion 25 时,我仍然无法访问 startForegroundService() 方法。

这些是我的 gradle 设置。

compileSdkVersion 25
buildToolsVersion "25.0.3"

defaultConfig {

minSdkVersion 21
targetSdkVersion 25
}

最佳答案

startForegroundService()可从 API 级别 25 的 API 级别 26 NOT 获得。

compileSdkVersion 25buildToolsVersion "25.0.3"改成最新的试试。

例如,在我的例子中,我使用的是:

compileSdkVersion 26
buildToolsVersion '27.0.3'

关于android - 如果我的应用程序针对牛轧糖设备,startService() 是否仍然有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50562718/

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