OSkillProxy — Android 组件调用代理
概述
OSkillProxy 是运行在 Android 设备上的代理服务。它提供本地 HTTP API,允许你以正确的 App 身份调用 Android 四大组件(Activity、Service、BroadcastReceiver、ContentProvider)。
使用前提:
- - OSkillProxy App 已安装并且代理服务已启动
- Token 已配置(在 App 界面上查看)
- 通过
http://127.0.0.1:8726 访问(端口可能已修改,以实际配置为准)
工具列表
start_activity
启动一个 Android Activity。
- - 支持显式 Intent(指定 package + class)和隐式 Intent(指定 action)
- 这是一个 fire-and-forget 操作,不返回 Activity 结果
start_service
启动一个 Android Service。
send_broadcast
发送一个 Android Broadcast。
query_provider
查询 ContentProvider 数据,返回结构化结果(列名 + 行数据)。
insert_provider
向 ContentProvider 插入数据,返回新记录的 URI。
update_provider
更新 ContentProvider 数据,返回受影响的行数。
delete_provider
删除 ContentProvider 数据,返回受影响的行数。
call_provider
调用 ContentProvider 的 call() 方法,返回 Bundle 结果。
调用方式
所有调用通过 HTTP POST 请求发起,使用 JSON 格式。
通用 HTTP 格式
CODEBLOCK0
认证
每个请求(除 GET /api/v1/status 外)必须携带 Authorization header:
CODEBLOCK1
通用响应格式
CODEBLOCK2
各端点详细说明
POST /component/activity/start
启动一个 Activity。
请求参数:
| 字段 | 类型 | 必填 | 说明 |
|---|
| package | string | 否 | 目标包名 |
| class |
string | 否 | 目标 Activity 完整类名(需同时指定 package) |
| action | string | 否 | Intent Action |
| categories | string[] | 否 | Intent Categories |
| data | string | 否 | Intent Data URI |
| type | string | 否 | MIME Type |
| extras | object | 否 | Intent Extras,见 extras 格式 |
| flags | string[] | 否 | Intent Flags 名称列表 |
INLINECODE1 +class(显式)或 action(隐式)至少提供一种。
支持的 Flags:
- - FLAGACTIVITYNEWTASK(自动添加)
- FLAGACTIVITYCLEARTOP
- FLAGACTIVITYSINGLETOP
- FLAGACTIVITYCLEARTASK
- FLAGACTIVITYNOHISTORY
- FLAGACTIVITYEXCLUDEFROMRECENTS
- FLAGACTIVITYNEWDOCUMENT
- FLAGACTIVITYMULTIPLETASK
- FLAGINCLUDESTOPPEDPACKAGES
POST /component/service/start
启动一个 Service。
请求参数: 同 Activity,额外字段:
| 字段 | 类型 | 必填 | 说明 |
|---|
| foreground | boolean | 否 | 是否以前台方式启动(Android 8.0+) |
POST /component/broadcast/send
发送一个 Broadcast。
请求参数: 同 Activity,额外字段:
| 字段 | 类型 | 必填 | 说明 |
|---|
| permission | string | 否 | 接收方需要持有的权限 |
POST /component/provider/query
查询 ContentProvider。
请求参数:
| 字段 | 类型 | 必填 | 说明 |
|---|
| uri | string | 是 | Content URI |
| projection |
string[] | 否 | 要查询的列 |
| selection | string | 否 | WHERE 条件(使用 ? 占位符) |
| selectionArgs | string[] | 否 | WHERE 参数值 |
| sortOrder | string | 否 | 排序规则 |
响应 data:
{
"columns": ["_id", "title"],
"rows": [[1, "Note 1"], [2, "Note 2"]],
"count": 2
}
POST /component/provider/insert
向 ContentProvider 插入数据。
请求参数:
| 字段 | 类型 | 必填 | 说明 |
|---|
| uri | string | 是 | Content URI |
| values |
object | 是 | 要插入的键值对,格式同 extras |
响应 data:
{
"uri": "content://com.example.provider/notes/3"
}
POST /component/provider/update
更新 ContentProvider 数据。
请求参数:
| 字段 | 类型 | 必填 | 说明 |
|---|
| uri | string | 是 | Content URI |
| values |
object | 是 | 要更新的键值对 |
| selection | string | 否 | WHERE 条件 |
| selectionArgs | string[] | 否 | WHERE 参数值 |
响应 data:
{
"affectedRows": 1
}
POST /component/provider/delete
删除 ContentProvider 数据。
请求参数:
| 字段 | 类型 | 必填 | 说明 |
|---|
| uri | string | 是 | Content URI |
| selection |
string | 否 | WHERE 条件 |
| selectionArgs | string[] | 否 | WHERE 参数值 |
响应 data:
{
"affectedRows": 1
}
POST /component/provider/call
调用 ContentProvider 的 call() 方法。
请求参数:
| 字段 | 类型 | 必填 | 说明 |
|---|
| uri | string | 是 | Content URI |
| method |
string | 是 | 方法名 |
| arg | string | 否 | 字符串参数 |
| extras | object | 否 | Bundle 参数(简单 key-value,自动推断类型) |
响应 data: ContentProvider 返回的 Bundle 内容,序列化为 JSON 对象。
extras 类型说明
extras 字段支持两种格式:
格式 1:显式类型(推荐)
CODEBLOCK7
支持的类型:string, int, long, float, double, boolean, string_array, int_array, INLINECODE12
格式 2:自动推断
{
"key": "hello",
"count": 42,
"flag": true
}
自动根据 JSON 值类型推断。
使用示例
示例 1:启动一个 Activity(显式 Intent)
场景:启动录音应用的透明 Activity 进行录音控制
CODEBLOCK9
示例 2:启动一个 Activity(隐式 Intent,带 extras)
CODEBLOCK10
示例 3:查询 ContentProvider
CODEBLOCK11
示例 4:发送 Broadcast
CODEBLOCK12
示例 5:检查服务状态(无需 Token)
CODEBLOCK13
错误码
请求格式错误 |
| 401 | 认证失败 |
| 404 | 端点不存在 |
| 1001 | Activity 启动失败 |
| 1002 | Service 启动失败 |
| 1003 | Broadcast 发送失败 |
| 1004 | Provider query 失败 |
| 1005 | Provider insert 失败 |
| 1006 | Provider update 失败 |
| 1007 | Provider delete 失败 |
| 1008 | Provider call 失败 |
状态检查
GET /api/v1/status
无需认证,用于检查代理服务是否运行。
响应:
CODEBLOCK14
OSkillProxy — Android 组件调用代理
概述
OSkillProxy 是运行在 Android 设备上的代理服务。它提供本地 HTTP API,允许你以正确的 App 身份调用 Android 四大组件(Activity、Service、BroadcastReceiver、ContentProvider)。
使用前提:
- - OSkillProxy App 已安装并且代理服务已启动
- Token 已配置(在 App 界面上查看)
- 通过 http://127.0.0.1:8726 访问(端口可能已修改,以实际配置为准)
工具列表
start_activity
启动一个 Android Activity。
- - 支持显式 Intent(指定 package + class)和隐式 Intent(指定 action)
- 这是一个 fire-and-forget 操作,不返回 Activity 结果
start_service
启动一个 Android Service。
send_broadcast
发送一个 Android Broadcast。
query_provider
查询 ContentProvider 数据,返回结构化结果(列名 + 行数据)。
insert_provider
向 ContentProvider 插入数据,返回新记录的 URI。
update_provider
更新 ContentProvider 数据,返回受影响的行数。
delete_provider
删除 ContentProvider 数据,返回受影响的行数。
call_provider
调用 ContentProvider 的 call() 方法,返回 Bundle 结果。
调用方式
所有调用通过 HTTP POST 请求发起,使用 JSON 格式。
通用 HTTP 格式
bash
curl -X POST http://127.0.0.1:8726/api/v1/component/ \
-H Authorization: Bearer \
-H Content-Type: application/json \
-d
认证
每个请求(除 GET /api/v1/status 外)必须携带 Authorization header:
Authorization: Bearer <你的token>
通用响应格式
json
{
success: true,
code: 0,
message: ok,
data: {},
requestId: abc12345
}
各端点详细说明
POST /component/activity/start
启动一个 Activity。
请求参数:
| 字段 | 类型 | 必填 | 说明 |
|---|
| package | string | 否 | 目标包名 |
| class |
string | 否 | 目标 Activity 完整类名(需同时指定 package) |
| action | string | 否 | Intent Action |
| categories | string[] | 否 | Intent Categories |
| data | string | 否 | Intent Data URI |
| type | string | 否 | MIME Type |
| extras | object | 否 | Intent Extras,见 extras 格式 |
| flags | string[] | 否 | Intent Flags 名称列表 |
package+class(显式)或 action(隐式)至少提供一种。
支持的 Flags:
- - FLAGACTIVITYNEWTASK(自动添加)
- FLAGACTIVITYCLEARTOP
- FLAGACTIVITYSINGLETOP
- FLAGACTIVITYCLEARTASK
- FLAGACTIVITYNOHISTORY
- FLAGACTIVITYEXCLUDEFROMRECENTS
- FLAGACTIVITYNEWDOCUMENT
- FLAGACTIVITYMULTIPLETASK
- FLAGINCLUDESTOPPEDPACKAGES
POST /component/service/start
启动一个 Service。
请求参数: 同 Activity,额外字段:
| 字段 | 类型 | 必填 | 说明 |
|---|
| foreground | boolean | 否 | 是否以前台方式启动(Android 8.0+) |
POST /component/broadcast/send
发送一个 Broadcast。
请求参数: 同 Activity,额外字段:
| 字段 | 类型 | 必填 | 说明 |
|---|
| permission | string | 否 | 接收方需要持有的权限 |
POST /component/provider/query
查询 ContentProvider。
请求参数:
| 字段 | 类型 | 必填 | 说明 |
|---|
| uri | string | 是 | Content URI |
| projection |
string[] | 否 | 要查询的列 |
| selection | string | 否 | WHERE 条件(使用 ? 占位符) |
| selectionArgs | string[] | 否 | WHERE 参数值 |
| sortOrder | string | 否 | 排序规则 |
响应 data:
json
{
columns: [_id, title],
rows: [[1, Note 1], [2, Note 2]],
count: 2
}
POST /component/provider/insert
向 ContentProvider 插入数据。
请求参数:
| 字段 | 类型 | 必填 | 说明 |
|---|
| uri | string | 是 | Content URI |
| values |
object | 是 | 要插入的键值对,格式同 extras |
响应 data:
json
{
uri: content://com.example.provider/notes/3
}
POST /component/provider/update
更新 ContentProvider 数据。
请求参数:
| 字段 | 类型 | 必填 | 说明 |
|---|
| uri | string | 是 | Content URI |
| values |
object | 是 | 要更新的键值对 |
| selection | string | 否 | WHERE 条件 |
| selectionArgs | string[] | 否 | WHERE 参数值 |
响应 data:
json
{
affectedRows: 1
}
POST /component/provider/delete
删除 ContentProvider 数据。
请求参数:
| 字段 | 类型 | 必填 | 说明 |
|---|
| uri | string | 是 | Content URI |
| selection |
string | 否 | WHERE 条件 |
| selectionArgs | string[] | 否 | WHERE 参数值 |
响应 data:
json
{
affectedRows: 1
}
POST /component/provider/call
调用 ContentProvider 的 call() 方法。
请求参数:
| 字段 | 类型 | 必填 | 说明 |
|---|
| uri | string | 是 | Content URI |
| method |
string | 是 | 方法名 |
| arg | string | 否 | 字符串参数 |
| extras | object | 否 | Bundle 参数(简单 key-value,自动推断类型) |
响应 data: ContentProvider 返回的 Bundle 内容,序列化为 JSON 对象。
extras 类型说明
extras 字段支持两种格式:
格式 1:显式类型(推荐)
json
{
key: {type: string, value: hello},
count: {type: int, value: 42},
flag: {type: boolean, value: true}
}
支持的类型:string, int, long, float, double, boolean, stringarray, intarray, long_array
格式 2:自动推断
json
{
key: hello,
count: 42,
flag: true
}
自动根据 JSON 值类型推断。
使用示例
示例 1:启动一个 Activity(显式 Intent)
场景:启动录音应用的透明 Activity 进行录音控制
bash
curl -X POST http://127.0.0.1:8726/api/v1/component/activity/start \
-H Authorization: Bearer a3f8xxxxxxxxxxc9d2 \
-H Content-Type: application/json \
-d {
package: com.coloros.soundrecorder,
class: oplus.multimedia.soundrecorder.slidebar.TransparentActivity,
action: oplus.intent.action.STARTRECORDFROMCUBEBUTTON,
categories: [android.intent.category.DEFAULT]
}
示例 2:启动一个 Activity(隐式 Intent,带 extras)
bash
curl -X POST http://127.0.0.1:8726/api/v1/component/activity/start \
-H Authorization: Bearer \
-H Content-Type: application/json \
-d {
action: android.intent.action.SEND,
type: text/plain,
extras: {
android.intent.extra.TEXT: {type: string, value: Hello from agent!}
}
}
示例 3:查询 ContentProvider
bash
curl -X POST http://127.