【问题标题】:What is Android's <instrumentation> tag equivalent in phonegap什么是 Android 的 <instrumentation> 标签在 phonegap 中等效
【发布时间】:2018-01-24 13:10:27
【问题描述】:
我们需要在我们的一个 phonegap 应用中启用instrumentation。给定的链接显示了如何为 android 本机应用程序启用它,但我无法弄清楚如何在 phonegap 应用程序上完成相同的操作。有没有办法将它添加到config.xml?如果有一种方法可以同时适用于 android 和 iOS,还是我们需要做一些额外的事情来在 iOS 中启用检测?
PS:我知道会有标准的 cmets,比如分享你的代码。但不幸的是,我目前没有任何代码可以分享,因为我不知道如何将其翻译为在config.xml 中工作。
【问题讨论】:
标签:
android
ios
cordova
phonegap
instrumentation
【解决方案1】:
有没有办法将它添加到config.xml?
这很简单:使用最新版本的 Phonegap/Cordova,您只需在您的 config.xml 中插入一个 <config-file> 块,如下所示:
<platform name="android">
<config-file target="AndroidManifest.xml" parent="/manifest">
<instrumentation android:functionalTest="false"
android:handleProfiling="true"
android:icon="drawable resource"
android:label="string resource"
android:name="com.example.project.Instrumentation"
android:targetPackage="com.example.myApp"
android:targetProcesses="*" />
</config-file>
</platform>
但是,核心 Phonegap (Cordova) 框架本身没有内置的检测功能,因此您必须自己编写 Instrumentation 类的原生 Android 实现。
最好将其封装为 Phonegap 插件,其中包括您的自定义 Java 类,<config-file> 块将进入plugin.xml。
有关详细信息,请参阅Plugin Development Guide。
如果有一种方法可以同时适用于 android 和 iOS,还是我们需要做一些额外的事情来在 iOS 中启用检测?
<instrumentation> 标签和相关类是特定于 Android 平台的,因此需要不同的 iOS 特定实现;关于这一点,我不知道:-)
如果您正在寻找开箱即用的解决方案,我相信有一些现有的插件,例如 dynatrace-cordova-plugin,它提供了某种 Javascript 级别的工具。