android - 测试 Activity 识别转换 API

标签 android android-activity transition

我目前正在开发一个使用 Activity Recognition Transition API 的应用程序(新的,不是旧的,请查看下面的链接)。我的问题是,如何测试我的应用程序?更确切地说,我如何“手动”触发转换事件?我真的必须将手机和笔记本电脑放入背包并骑自行车骑行才能触发 ON_BYCICLE/ACTIVITY_TRANSITION_ENTER 事件吗?一定有更简单的方法 :) 也许使用 adb? https://developer.android.com/studio/test/command-line

API 文档:https://developer.android.com/guide/topics/location/transitions

最佳答案

您可以使用下面的代码来模拟事件

        var intent = Intent()

        // Your broadcast receiver action

        intent.action = BuildConfig.APPLICATION_ID + "TRANSITIONS_RECEIVER_ACTION"
        var events: ArrayList<ActivityTransitionEvent> = arrayListOf()

        // You can set desired events with their corresponding state

        var transitionEvent = ActivityTransitionEvent(DetectedActivity.IN_VEHICLE, ActivityTransition.ACTIVITY_TRANSITION_ENTER, SystemClock.elapsedRealtimeNanos())
        events.add(transitionEvent)
        var result = ActivityTransitionResult(events)
        SafeParcelableSerializer.serializeToIntentExtra(result, intent, "com.google.android.location.internal.EXTRA_ACTIVITY_TRANSITION_RESULT")
        activity?.sendBroadcast(intent)

我在我的应用程序中创建了带有两个按钮的简单 Activity ,我在其中分别广播这些事件(开始和停止)。这有助于我优雅地调试应用程序。

关于android - 测试 Activity 识别转换 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55079859/

相关文章:

java - 是否有适用于 Google Android 的表单设计器

android - 在我的布局文件中引用内置主题中的颜色

android - 数据传递到 Android 中的另一个应用程序

android - 膨胀第二个导航主机时,应用程序崩溃

transition - Vue.js 页面过渡淡入淡出效果与 vue-router

swift - 返回过渡上的黑边

android - android XML文件中的下划线与句点

java - 如何使用HttpClient下载连续数据流?

java - 如何将首选项值获取到静态字符串变量中?

CSS 过渡属性不能用于选择器两次?