Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
取酒独倾
unidocs-zh
提交
8ce5b8f8
U
unidocs-zh
项目概览
取酒独倾
/
unidocs-zh
与 Fork 源项目一致
Fork自
DCloud / unidocs-zh
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
unidocs-zh
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
8ce5b8f8
编写于
9月 02, 2022
作者:
打打卡夫卡
提交者:
Gitee
9月 02, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update docs/plugin/uts-plugin.md.
Signed-off-by:
杜庆泉
<
zmobs0@163.com
>
上级
c58c757c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
28 addition
and
10 deletion
+28
-10
docs/plugin/uts-plugin.md
docs/plugin/uts-plugin.md
+28
-10
未找到文件。
docs/plugin/uts-plugin.md
浏览文件 @
8ce5b8f8
...
...
@@ -100,6 +100,7 @@ package.json的完整文档[详见](uni_modules.md#package.json)
<pre
v-pre=
""
data-lang=
""
>
<code
class=
"lang-"
style=
"padding:0"
>
┌─utssdk
│ ├─app-android //Android平台目录
│ │ └─index.uts
...
...
@@ -109,7 +110,7 @@ package.json的完整文档[详见](uni_modules.md#package.json)
│ │ └─config.json //ios原生配置
│ ├─web //web平台目录
│ │ └─index.uts
│ └─mp-xxx // 其他平台
,待实现
│ └─mp-xxx // 其他平台
├─common // 可跨端公用的uts代码。推荐,不强制
├─static // 静态资源
├─package.json
...
...
@@ -281,34 +282,49 @@ import { getAppContext } from "io.dcloud.uts.android";
### getAppContext
获取当前应用Application上下文,对应android平台上的application context
获取当前应用Application上下文,对应android平台 Context.getApplicationContext 函数实现
Android开发场景中,调用应用级别的资源/能力,需要使用此上下文。更多用法,参考
[
Android官方文档
](
)
```
ts
fun
getAppContext
():
Context
?
// [示例]获取asset下的音频,并且播放
let
assetManager
=
getAppContext
()
!
.
getAssets
();
let
afd
=
assetManager
.
openFd
(
"
free.mp3
"
);
let
mediaPlayer
=
new
MediaPlayer
();
mediaPlayer
.
setDataSource
(
afd
.
getFileDescriptor
(),
afd
.
getStartOffset
(),
afd
.
getLength
());
mediaPlayer
.
prepare
();
mediaPlayer
.
start
();
```
### getUniActivity
获取当前应用宿主activity示例,当前 uni-app 应用实例的宿主activity
获取当前插件所属的activity实例,对应android平台 getActivity 函数实现
Android开发场景中,调用活动的级别的资源/能力,需要使用此上下文。更多用法,参考
[
Android官方文档
](
)
```
ts
fun
getUniActivity
():
Context
?
// [示例]获取当前activity顶层容器
let
frameContent
=
decorView
.
findViewById
<
FrameLayout
>
(
android
.
R
.
id
.
content
)
```
### getResourcePath(resourceName:String)
获取指定插件资源 的运行期绝对路径
```
ts
fun
getResourcePath
(
resourceName
:
String
):
String
```
比如,插件A使用到了一张图片,开发期间 存放位置为
`uni_modules/test-uts-static/static/logo.png`
程序运行期间,需要获取到此资源,可以使用
```
ts
// [示例]获取指定资源路径
// 得到文件运行时路径: `/storage/emulated/0/Android/data/io.dcloud.HBuilder/apps/__UNI__3732623/www/uni_modules/test-uts-static/static/logo.png`
getResourcePath
(
"
uni_modules/test-uts-static/static/logo.png
"
)
```
得到文件运行时路径:
`/storage/emulated/0/Android/data/io.dcloud.HBuilder/apps/__UNI__3732623/www/uni_modules/test-uts-static/static/logo.png`
### onAppActivityPause
...
...
@@ -326,6 +342,7 @@ getResourcePath("uni_modules/test-uts-static/static/logo.png")
容器的宿主activity 回退物理按键点击时触发
## 常见问题
### 常见报错
...
...
@@ -346,7 +363,8 @@ let textSize = 30.0.toFloat();
android中UI相关的api,很多会要求泛型,目前uts支持用as关键字强转,满足类似的场景
```
ts
let
frameContent
=
decorView
.
findViewById
(
android
.
R
.
id
.
content
)
as
FrameLayout
let
frameContent
=
decorView
.
findViewById
<
FrameLayout
>
(
android
.
R
.
id
.
content
)
let
layoutParam
=
new
FrameLayout
.
LayoutParams
(
ViewGroup
.
LayoutParams
.
MATCH_PARENT
,
ViewGroup
.
LayoutParams
.
WRAP_CONTENT
);
```
## 路线图
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录