- system_info.py: Environment 存储目录 + Build 构建信息 + Log 日志 + platform (转译层核心 API) - file_manager.py: Environment 外部存储 + 列目录/写文本/读文本 (真实文件系统操作) - intent_builder.py: Intent ACTION_VIEW/ACTION_SEND + Uri 解析 + putExtra (组件通信) - 全链路验证: list 识别 4 脚本 7 工具; run 全部 success (含 Log I/W 输出) - 配套修复 android_pyapi (Intent.EXTRA_TEXT 挂载, 已推送 Gitee e2f78f3)
77 lines
2.6 KiB
Python
77 lines
2.6 KiB
Python
# METADATA
|
||
# {
|
||
# "name": "intent_builder",
|
||
# "display_name": {
|
||
# "zh": "Intent 意图构建器",
|
||
# "en": "Intent Builder"
|
||
# },
|
||
# "description": {
|
||
# "zh": "用 android.content.Intent 构建意图:ACTION_VIEW 打开 URL、ACTION_SEND 分享文本,解析 Uri,并用 Log 输出。",
|
||
# "en": "Build intents with android.content.Intent: ACTION_VIEW for URLs, ACTION_SEND for sharing text, parse Uri, log via Log."
|
||
# },
|
||
# "category": "System",
|
||
# "tools": [
|
||
# {
|
||
# "name": "build_view_intent",
|
||
# "description": {
|
||
# "zh": "构建 ACTION_VIEW 意图(打开 URL)",
|
||
# "en": "Build ACTION_VIEW intent (open URL)"
|
||
# },
|
||
# "parameters": [
|
||
# { "name": "url", "description": { "zh": "要打开的网址", "en": "URL to open" }, "type": "string", "required": true }
|
||
# ]
|
||
# },
|
||
# {
|
||
# "name": "build_share_intent",
|
||
# "description": {
|
||
# "zh": "构建 ACTION_SEND 分享意图",
|
||
# "en": "Build ACTION_SEND share intent"
|
||
# },
|
||
# "parameters": [
|
||
# { "name": "text", "description": { "zh": "分享的文本", "en": "Text to share" }, "type": "string", "required": true }
|
||
# ]
|
||
# }
|
||
# ]
|
||
# }
|
||
|
||
TAG = "IntentBuilder"
|
||
|
||
|
||
async def build_view_intent(params):
|
||
url = (params or {}).get("url", "")
|
||
if not url:
|
||
raise Exception("url 不能为空")
|
||
intent = Intent(Intent.ACTION_VIEW)
|
||
intent.setData(Uri.parse(url))
|
||
Log.i(TAG, f"ACTION_VIEW -> {url}")
|
||
result = {
|
||
"action": intent.getAction(),
|
||
"data": intent.getData(),
|
||
"flags": intent.getFlags(),
|
||
"resolved": intent.toString(),
|
||
}
|
||
complete({"success": True, "message": "意图构建成功(桌面环境不实际拉起)", "data": result})
|
||
return result
|
||
|
||
|
||
async def build_share_intent(params):
|
||
text = (params or {}).get("text", "")
|
||
if not text:
|
||
raise Exception("text 不能为空")
|
||
intent = Intent(Intent.ACTION_SEND)
|
||
intent.setType("text/plain")
|
||
intent.putExtra(Intent.EXTRA_TEXT, text)
|
||
Log.i(TAG, f"ACTION_SEND: {text[:40]}")
|
||
result = {
|
||
"action": intent.getAction(),
|
||
"type": intent.getType(),
|
||
"extras": intent.getExtras(),
|
||
"resolved": intent.toString(),
|
||
}
|
||
complete({"success": True, "message": "分享意图构建成功", "data": result})
|
||
return result
|
||
|
||
|
||
exports.build_view_intent = build_view_intent
|
||
exports.build_share_intent = build_share_intent
|