- 语法:
<instrumentation android:functionalTest=["true" | "false"] android:handleProfiling=["true" | "false"] android:icon="drawable resource" android:label="string resource" android:name="string" android:targetPackage="string" android:targetProcesses="string" />
- 包含于:
<manifest>
- 说明:
- 声明用于监控应用与系统交互的
Instrumentation
类。Instrumentation
对象在应用的所有组件之前进行实例化。 - 属性:
android:functionalTest
Instrumentation
类是否作为功能测试运行。 如果是,则为true
,否则为false
。默认值为false
。android:handleProfiling
Instrumentation
对象是否开启和关闭性能剖析。如果其确定何时开始和停止性能分析,则为true
;如果在整个运行过程中持续进行性能分析,则为false
。如果值为true
,可让对象将分析目标设定为一组特定的操作。默认值为false
。android:icon
- 一个表示
Instrumentation
类的图标。必须将此属性设为对可绘制资源的引用。 android:label
Instrumentation
类的一种用户可读标签。可以将该标签设为原始字符串或对字符串资源的引用。android:name
Instrumentation
子类的名称。 请使用完全限定类名称,例如com.example.project.StringInstrumentation
。不过,作为一种简写形式,如果名称的第一个字符是句点,则会将其附加到<manifest>
元素中指定的软件包名称。没有默认值。必须指定此名称。
android:targetPackage
- 表示
Instrumentation
对象针对哪个应用运行。应用由通过<manifest>
元素在其清单文件中分配的软件包名称进行标识。 android:targetProcesses
表示
Instrumentation
对象针对哪些进程运行。如果以逗号分隔列表的形式列出了进程,表示将针对这些特定的进程运行插桩测试。如果值为"*"
,表示将针对在android:targetPackage
中定义的应用的所有进程运行插桩测试。如果未在清单中提供此值,将仅针对在
android:targetPackage
中定义的应用的主进程运行插桩测试。此属性是在 API 级别 26 中添加的。
- 引入于:
- API 级别 1
<插桩>
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# <instrumentation\u003e\n\nsyntax:\n:\n\n ```xml\n \u003cinstrumentation android:functionalTest=[\"true\" | \"false\"]\n android:handleProfiling=[\"true\" | \"false\"]\n android:icon=\"drawable resource\"\n android:label=\"string resource\"\n android:name=\"string\"\n android:targetPackage=\"string\"\n android:targetProcesses=\"string\" /\u003e\n ```\n\ncontained in:\n: [\u003cmanifest\u003e](/guide/topics/manifest/manifest-element)\n\ndescription:\n: Declares an [Instrumentation](/reference/android/app/Instrumentation) class that lets you\n monitor an application's interaction with the system. The `Instrumentation`\n object is instantiated before any of the application's components.\n\nattributes:\n:\n\n `android:functionalTest`\n : Whether the `Instrumentation` class runs as a functional test.\n This is `true` if it does and `false` if not. The\n default value is `false`.\n\n `android:handleProfiling`\n : Whether the `Instrumentation` object turns profiling on and\n off. This is `true` if it determines when profiling starts and\n stops and `false` if profiling continues the entire time it is\n running. A value of `true` enables the object to target profiling\n at a specific set of operations. The default value is `false`.\n\n `android:icon`\n : An icon that represents the `Instrumentation` class. This attribute\n must be set as a reference to a drawable resource.\n\n `android:label`\n : A user-readable label for the `Instrumentation` class. The label\n can be set as a raw string or a reference to a string resource.\n\n `android:name`\n : The name of the `Instrumentation` subclass.\n Use a fully qualified class name, such as\n `com.example.project.StringInstrumentation`. However, as a shorthand,\n if the first character of the name is a period, it is appended to the package\n name specified in the [\u003cmanifest\u003e](/guide/topics/manifest/manifest-element) element.\n\n\n There is no default. The name must be specified.\n\n `android:targetPackage`\n : The application that the `Instrumentation` object runs\n against. An application is identified by the package name assigned in its\n manifest file by the `\u003cmanifest\u003e` element.\n\n `android:targetProcesses`\n\n : The processes that the `Instrumentation` object\n runs against. A comma-separated list indicates that the instrumentation runs\n against those specific processes. A value of `\"*\"` indicates that the\n instrumentation runs against all processes of the app defined in\n `android:targetPackage`.\n\n If this value isn't provided in the manifest, the instrumentation runs\n only against the main process of the app defined in\n `android:targetPackage`.\n\n This attribute was added in API level 26.\n\nintroduced in:\n: API level 1"]]