简体   繁体   English

当我尝试使用 Google 活动识别转换 API 开发 GPS 跟踪 Android APP 时,我遇到了 API 工作停止问题

[英]When i was trying to developing GPS tracking Android APP with Google Activity Recognition Transition API, I had a API-working stop issue

When i was trying to developing GPS tracking Android APP with Google Activity Recognition Transition API, I had a API-working stop issue.当我尝试使用 Google 活动识别转换 API 开发 GPS 跟踪 Android APP 时,我遇到了 API 工作停止问题。

I thought that it is a problem of device-model compatible but not sure exactly about it because it occurs very irregulary and dose not process any error log for it.我认为这是一个设备模型兼容的问题,但不确定它到底是什么,因为它发生得非常不规则,并且不会为它处理任何错误日志。

If someone has know about the solution, please give me some good advise for it.如果有人知道该解决方案,请给我一些好的建议。

I really appreciate for hearing some good advise to solve this problem.我真的很感激听到一些很好的建议来解决这个问题。

  1. Android device information: Android 设备信息:

    SDK_INT: 31 SDK_INT:31

    RELEASE: 12发布:12

    BRAND: samsung品牌:三星

  2. An explanation for when not working Transition API: Transition API 不工作时的解释:

First of all, Transition API is working good under to device model 'Android 12'.首先,Transition API 在设备 model“Android 12”下运行良好。

But when I try to test on 12 or over version, the API-stoping problem is occurs in 1 days to 1 week.但是当我尝试在 12 或更高版本上进行测试时,API 停止问题会在 1 天到 1 周内发生。

Also the problem dose not make any error log to find and analysis the exact problem.此外,该问题不做任何错误日志来查找和分析确切的问题。

Stoped Google Activity Recognition Transition API will work when reboots the device, but not work with re-installation.停止的 Google 活动识别转换 API 将在重新启动设备时起作用,但不适用于重新安装。

Other APP that using Transition API having no problem while my APP is not working.使用 Transition API 的其他 APP 在我的 APP 无法运行时没有问题。

Also, other APP and my APP can be not working when the Transition API is stopped.此外,当 Transition API 停止时,其他应用程序和我的应用程序可能无法运行。

3.Installation in test-phone 3.测试机安装

  1. Build the Apk or generate a Signed Build generate Signed Build or Apk and upload the构建 Apk 或生成 Signed Build 生成 Signed Build 或 Apk 并上传

  2. The same problem has occurred when try to test with the uploaded internal version of google 'Play Store'尝试使用上传的谷歌“Play Store”内部版本进行测试时出现了同样的问题

4.Sorce explanation 4.来源说明

My app has one foregound service is runing.我的应用程序有一项前台服务正在运行。

When the APP is executed first time, the Transition API is runing that insideof the foreground service. APP第一次执行时,Transition API在前台服务内部运行。

How to activate the API:如何激活API:


val intent = Intent(ACTIVITY_RECOGNITION_EVENT)
val pendingIntent = PendingIntent.getBroadcast(context, 0, intent, if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
    PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
} else {
    PendingIntent.FLAG_UPDATE_CURRENT
})

... 

val activityRecognitionClient = ActivityRecognition.getClient(context)
// val interval = 20 * 1000L
val interval = 3 * 60 * 1000L
val task = activityRecognitionClient.requestActivityUpdates(interval, pendingIntent)
task.addOnSuccessListener {
    ...
}
task.addOnCompleteListener {
    ...
}
task.addOnCanceledListener {
    ...
}
task.addOnFailureListener {
    ...
}

// createRequest skip

val activityRecognitionClient = ActivityRecognition.getClient(context)
val task = activityRecognitionClient.requestActivityTransitionUpdates(
    createRequest(),
    pendingIntent
)
task.addOnSuccessListener {
    ...
}
task.addOnCanceledListener {
    ...
}
task.addOnFailureListener {
    ...
}
task.addOnCompleteListener {
    ...
}

// In receiver, it work like this:
private val transitionsReceiver = object: BroadcastReceiver() {
    override fun onReceive(_context: Context, intent: Intent) {
        if (ActivityRecognitionResult.hasResult(intent)) {
            val result = ActivityRecognitionResult.extractResult(intent)
            ...
        }
        else if (ActivityTransitionResult.hasResult(intent)) {
            val result = ActivityTransitionResult.extractResult(intent)
            ...
        }
    }
}

val intentFilter = IntentFilter()
intentFilter.addAction(ACTIVITY_RECOGNITION_EVENT)
context.registerReceiver(transitionsReceiver, intentFilter)

Is there any one having this problem?有人遇到这个问题吗?

I'm still working on this problem but can not find the reason of the Google Activity Recognition Transition API stopping.我仍在解决这个问题,但找不到 Google Activity Recognition Transition API 停止的原因。

I would like to know any advice or hint for solving this and appreciate it for your comment.我想知道解决此问题的任何建议或提示,并感谢您的评论。

Am I miss something or having wrong point?我错过了什么或有错误的观点吗?

I'm having the same issue as you.我和你有同样的问题。 It happens on both Sampling API and Transition API. We noticed on multiple Samsung devices but not sure if it is happening on other.它发生在 Sampling API 和 Transition API 上。我们注意到多台三星设备,但不确定它是否发生在其他设备上。 I opened a issue on tracker我在跟踪器上打开了一个问题

I'm having a similar issue.我有一个类似的问题。 Currently what I've found is that when my app can retrieve Sensor.TYPE_SIGNIFICANT_MOTION then Activity Transitions updates come in correctly, but then at some point, sensor is null in my logs and I receive no updates whatsoever.目前我发现,当我的应用程序可以检索Sensor.TYPE_SIGNIFICANT_MOTION时, Activity Transitions更新会正确进入,但在某些时候,传感器在我的日志中为 null,我没有收到任何更新。 Feels to me that OS blocks this sensor at some point (allows it to fall in deep sleep) and then there's no coming back.在我看来,操作系统会在某个时候阻止该传感器(允许它进入深度睡眠),然后就不会再回来了。 :( :(

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

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