使用监听器或广播接收器进行 Android Activity 识别?

标签 android google-play-services

我想知道,为什么 ActivityRecognitionClient 没有方法以标准 java 监听器作为参数来请求更新?更奇怪的是,同时 LocationСlient 有 such method效果很好。

Official example Activity 识别看起来很糟糕。很多耦合和样板代码。看起来 IntentService 是处理来自 ActivityRecognitionClient 的更新的唯一变体。这非常不舒服。

@Android 团队的伙计们,为什么会这样?

作为开发者,我希望在下一版本的 Google Play 服务中看到 requestActivityUpdates(interval, listener) 方法。

目前,有谁知道是否可以使用 BroadcastReceiver 来处理来自 ActivityRecognitionClient 的更新?

最佳答案

I'm wondering, why ActivityRecognitionClient has no method to request updates with standard java listener as parameter?

许多好的问题会产生某种程度的基于专家经验的意见,但这个问题的答案往往几乎完全基于意见,而不是事实、引用或特定专业知识。

除此之外,引用 the documentation对于 requestActivityUpdates():

A common use case is that an application wants to monitor activities in the background and perform an action when a specific activity is detected. To do this without needing a service that is always on in the background consuming resources, detected activities are delivered via an intent. The application specifies a PendingIntent callback (typically an IntentService) which will be called when activities are detected.

It looks like IntentService is sole variant for handling updates from ActivityRecognitionClient.

不是。

For now, does anyone know, is it possible to use BroadcastReceiver for handling updates from ActivityRecognitionClient?

PendingIntent 有多种类型,由各种工厂方法创建。该示例显示使用 getService() 创建将调用 startService()PendingIntent。欢迎您使用任何其他 PendingIntent,例如 getBroadcast() 中的一个,它将调用 sendBroadcast()

关于使用监听器或广播接收器进行 Android Activity 识别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17445765/

相关文章:

android - AndroidManifest 中的 Google Play Services v13 错误元数据

android - com.viewpagerindicator.CirclePageIndicator 出错

java - OpenCV 用 java 中的另一个值替换特定像素值

android - Flutter - ListView 中的交互式 ListTile

java - 如何在 Android Studio 中为静态导入修复 "Organize Imports"

android - ScrollView 中的 MapFragment

java - 如何在反序列化期间获取对 Android Context 的引用?

android - Google Auth错误-com.google.android.gms.auth.UserRecoverableAuthException:NeedPermission

android - 如何在 Android 中以编程方式打开/更改 Google Ads 选择退出设置?

google-api - 将多个项目 ID 连接到 Google Play Developer Console