简体   繁体   English

后台定位应用程序在三星 Android 8.0 设备中不起作用

[英]Background location app not work in Samsung Android 8.0 devices

I have a location application that runs in background.我有一个在后台运行的定位应用程序。 To manage all this, I use periodic alarms to activate the localization process.为了管理这一切,我使用定期警报来激活本地化过程。 The problem is that since the last update of SAMSUNG has stopped working on these devices.问题是自从SAMSUNG 上次更新后,这些设备就停止工作了。 When the device is locked those alarms stop working.当设备被锁定时,这些警报停止工作。 Just by activating the screen again, everything works correctly.只需再次激活屏幕,一切正常。 I have tried several methods for managing alarms and the last tests have been done with the setExactAndAllowWhileIdle method我尝试了几种管理警报的方法,最后的测试是使用setExactAndAllowWhileIdle方法完成的

https://developer.android.com/reference/android/app/AlarmManager.html#setExactAndAllowWhileIdle(int,%20long,%20android.app.PendingIntent) https://developer.android.com/reference/android/app/AlarmManager.html#setExactAndAllowWhileIdle(int,%20long,%20android.app.PendingIntent)

But the result has been the same.但结果是一样的。 This behavior happens to me on Samsung devices with Android 8.0 .这种行为发生在我的Android 8.0 三星设备上

Any help or suggestion will be welcome.欢迎任何帮助或建议。

Thank you in advance先感谢您

Use Broadcast receiver to get location in version 8.0...i have test it was working for me使用广播接收器在 8.0 版中获取位置...我已经测试它对我有用

 private PendingIntent getPendingIntent() {
        // Note: for apps targeting API level 25 ("Nougat") or lower, either
        // PendingIntent.getService() or PendingIntent.getBroadcast() may be used when requesting
        // location updates. For apps targeting API level O, only
        // PendingIntent.getBroadcast() should be used. This is due to the limits placed on services
        // started in the background in "O".

        // TODO(developer): uncomment to use PendingIntent.getService().
//        Intent intent = new Intent(this, LocationUpdatesIntentService.class);
//        intent.setAction(LocationUpdatesIntentService.ACTION_PROCESS_UPDATES);
//        return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        Intent intent = new Intent(this, LocationUpdatesBroadcastReceiver.class);
        intent.setAction(LocationUpdatesBroadcastReceiver.ACTION_PROCESS_UPDATES);
        return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }

Reference : https://github.com/googlesamples/android-play-location/blob/master/LocationUpdatesPendingIntent/app/src/main/java/com/google/android/gms/location/sample/locationupdatespendingintent/MainActivity.java参考: https : //github.com/googlesamples/android-play-location/blob/master/LocationUpdatesPendingIntent/app/src/main/java/com/google/android/gms/location/sample/locationupdatespendingintent/MainActivity.java

Note: Some of device is not working like OPPO,Vivo, due to security reason.. In this case you have to go to Security permissions -> autostart -> then enable autostart from there.注意:由于安全原因,某些设备无法像 OPPO、Vivo 那样工作。在这种情况下,您必须转到Security permissions -> autostart -> 然后从那里启用自动启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM