Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
e02013bb
U
uni-api
项目概览
DCloud
/
uni-api
通知
669
Star
23
Fork
12
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-api
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
e02013bb
编写于
10月 31, 2024
作者:
张
张磊
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
支持chooseSystemMadia
上级
c93683eb
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
185 addition
and
49 deletion
+185
-49
uni_modules/uni-chooseSystemImage/changelog.md
uni_modules/uni-chooseSystemImage/changelog.md
+4
-0
uni_modules/uni-chooseSystemImage/package.json
uni_modules/uni-chooseSystemImage/package.json
+38
-36
uni_modules/uni-chooseSystemImage/utssdk/app-android/index.uts
...odules/uni-chooseSystemImage/utssdk/app-android/index.uts
+124
-12
uni_modules/uni-chooseSystemImage/utssdk/app-android/libs/chooseMedia-release.aar
...stemImage/utssdk/app-android/libs/chooseMedia-release.aar
+0
-0
uni_modules/uni-chooseSystemImage/utssdk/interface.uts
uni_modules/uni-chooseSystemImage/utssdk/interface.uts
+19
-1
未找到文件。
uni_modules/uni-chooseSystemImage/changelog.md
浏览文件 @
e02013bb
## 1.1.0(2024-10-31)
新增chooseSystemMedia,支持选择图片和视频。
## 1.0.0(2024-10-23)
新增插件
uni_modules/uni-chooseSystemImage/package.json
浏览文件 @
e02013bb
{
"id"
:
"uni-chooseSystemImage"
,
"displayName"
:
"uni-chooseSystem
Image
"
,
"version"
:
"1.
0
.0"
,
"description"
:
"
uni-chooseSystemImage
"
,
"displayName"
:
"uni-chooseSystem
Media
"
,
"version"
:
"1.
1
.0"
,
"description"
:
"
从手机相册中选择图片或视频,解决google play新政策禁止添加媒体权限的问题
"
,
"keywords"
:
[
"uni-chooseSystemImage"
"google"
,
"上架"
,
"图片选择"
],
"repository"
:
""
,
"engines"
:
{
"HBuilderX"
:
"^
3.6.8
"
"HBuilderX"
:
"^
4.29
"
},
"dcloudext"
:
{
"type"
:
"uts"
,
...
...
@@ -24,9 +26,9 @@
"qq"
:
""
},
"declaration"
:
{
"ads"
:
""
,
"data"
:
""
,
"permissions"
:
""
"ads"
:
"
无
"
,
"data"
:
"
本插件不会采集任何隐私信息,获取权限仅是为了兼容android12及以下版本的系统。
"
,
"permissions"
:
"
<uses-permission android:name=
\"
android.permission.READ_EXTERNAL_STORAGE
\"
/>
"
},
"npmurl"
:
""
},
...
...
@@ -35,47 +37,47 @@
"encrypt"
:
[],
"platforms"
:
{
"cloud"
:
{
"tcb"
:
"
u
"
,
"aliyun"
:
"
u
"
,
"alipay"
:
"
u
"
"tcb"
:
"
y
"
,
"aliyun"
:
"
y
"
,
"alipay"
:
"
y
"
},
"client"
:
{
"Vue"
:
{
"vue2"
:
"
u
"
,
"vue3"
:
"
u
"
"vue2"
:
"
n
"
,
"vue3"
:
"
n
"
},
"App"
:
{
"app-android"
:
"u"
,
"app-ios"
:
"u
"
,
"app-harmony"
:
"u
"
"app-android"
:
"u"
,
"app-ios"
:
"n
"
,
"app-harmony"
:
"n
"
},
"H5-mobile"
:
{
"Safari"
:
"
u
"
,
"Android Browser"
:
"
u
"
,
"微信浏览器(Android)"
:
"
u
"
,
"QQ浏览器(Android)"
:
"
u
"
"Safari"
:
"
n
"
,
"Android Browser"
:
"
n
"
,
"微信浏览器(Android)"
:
"
n
"
,
"QQ浏览器(Android)"
:
"
n
"
},
"H5-pc"
:
{
"Chrome"
:
"
u
"
,
"IE"
:
"
u
"
,
"Edge"
:
"
u
"
,
"Firefox"
:
"
u
"
,
"Safari"
:
"
u
"
"Chrome"
:
"
n
"
,
"IE"
:
"
n
"
,
"Edge"
:
"
n
"
,
"Firefox"
:
"
n
"
,
"Safari"
:
"
n
"
},
"小程序"
:
{
"微信"
:
"
u
"
,
"阿里"
:
"
u
"
,
"百度"
:
"
u
"
,
"字节跳动"
:
"
u
"
,
"QQ"
:
"
u
"
,
"钉钉"
:
"
u
"
,
"快手"
:
"
u
"
,
"飞书"
:
"
u
"
,
"京东"
:
"
u
"
"微信"
:
"
n
"
,
"阿里"
:
"
n
"
,
"百度"
:
"
n
"
,
"字节跳动"
:
"
n
"
,
"QQ"
:
"
n
"
,
"钉钉"
:
"
n
"
,
"快手"
:
"
n
"
,
"飞书"
:
"
n
"
,
"京东"
:
"
n
"
},
"快应用"
:
{
"华为"
:
"
u
"
,
"联盟"
:
"
u
"
"华为"
:
"
n
"
,
"联盟"
:
"
n
"
}
}
}
...
...
uni_modules/uni-chooseSystemImage/utssdk/app-android/index.uts
浏览文件 @
e02013bb
/* 引入 interface.uts 文件中定义的变量 */
import { ChooseSystemImage, ChooseSystemImageOptions, ChooseSystemImageSuccessResult, ChooseSystemVideo, ChooseSystemVideoOptions, ChooseSystemVideoSuccessResult } from '../interface.uts';
import { ChooseSystemImage, ChooseSystemImageOptions, ChooseSystemImageSuccessResult, ChooseSystem
Media, ChooseSystemMediaOptions, ChooseSystemMediaSuccessResult, ChooseSystem
Video, ChooseSystemVideoOptions, ChooseSystemVideoSuccessResult } from '../interface.uts';
import AppCompatActivity from 'androidx.appcompat.app.AppCompatActivity';
import ActivityResultCallback from 'androidx.activity.result.ActivityResultCallback';
import List from 'kotlin.collections.List';
...
...
@@ -23,6 +23,9 @@ import FileInputStream from 'java.io.FileInputStream';
import FileOutputStream from 'java.io.FileOutputStream';
import InputStream from 'java.io.InputStream';
import Build from 'android.os.Build';
import Parcelable from 'android.os.Parcelable';
import Media from 'uts.sdk.modules.uniChooseSystemImage.Media';
var resultCallback : ((requestCode : Int, resultCode : Int, data ?: Intent) => void) | null = null
export const chooseSystemImage : ChooseSystemImage = function (option : ChooseSystemImageOptions) {
...
...
@@ -45,22 +48,132 @@ export const chooseSystemImage : ChooseSystemImage = function (option : ChooseSy
}
}
function __chooseSystemImage(option : ChooseSystemImageOptions) {
export const chooseSystemMedia : ChooseSystemMedia = function (option : ChooseSystemMediaOptions) {
if (option.count <= 0) {
var error = new ImageErrorImpl(2101002, "uni-chooseSystemMedia")
option.fail?.(error)
option.complete?.(error)
return
}
if (option.count > 100) {
option.count = 100
}
if (Build.VERSION.SDK_INT > 32) {
__chooseSystemMedia(option)
} else {
UTSAndroid.requestSystemPermission(UTSAndroid.getUniActivity()!, [android.Manifest.permission.READ_EXTERNAL_STORAGE], (a : boolean, b : string[]) => {
__chooseSystemMedia(option)
}, (a : boolean, b : string[]) => {
var error = new ImageErrorImpl(2101005, "uni-chooseSystemMedia")
option.fail?.(error)
option.complete?.(error)
})
}
}
function __chooseSystemMedia(option : ChooseSystemMediaOptions) {
try {
resultCallback = (requestCode : Int, resultCode : Int, data : Intent | null) => {
UTSAndroid.offAppActivityResult(resultCallback!)
if (10086 == requestCode && resultCode == -1) {
if (data != null) {
var result = data!.get
String
ArrayExtra("paths")
var result = data!.get
Parcelable
ArrayExtra("paths")
if (result != null && result!.size > 0) {
var paths : Array<string> = []
result.forEach((p : string) => {
if (UTSAndroid.isUniAppX()) {
paths.push("file://" + (p))
} else {
paths.push("file://" + copyResource(p))
}
result.forEach((p : Parcelable) => {
if (p instanceof Media)
if (UTSAndroid.isUniAppX()) {
paths.push("file://" + (p.path!))
} else {
if (p.type == 1) {
paths.push("file://" + copyResource(p.path!))
} else {
paths.push("file://" + (p.path!))
}
}
})
var success : ChooseSystemMediaSuccessResult = {
filePaths: paths
}
option.success?.(success)
option.complete?.(success)
} else {
var error = new ImageErrorImpl(2101001, "uni-chooseSystemMedia")
option.fail?.(error)
option.complete?.(error)
}
} else {
var error = new ImageErrorImpl(2101001, "uni-chooseSystemMedia")
option.fail?.(error)
option.complete?.(error)
}
} else {
var error = new ImageErrorImpl(2101001, "uni-chooseSystemMedia")
option.fail?.(error)
option.complete?.(error)
}
}
UTSAndroid.onAppActivityResult(resultCallback!)
var intent = new Intent(UTSAndroid.getUniActivity()!, Class.forName("uts.sdk.modules.uniChooseSystemImage.ChooseSystemImageActivity"))
intent.putExtra("count", option.count)
if (option.mediaType != null) {
if (option.mediaType!.indexOf("mix") >= 0) {
intent.putExtra("type", 3)
} else if (option.mediaType!.indexOf("image") >= 0) {
intent.putExtra("type", 1)
} else if (option.mediaType!.indexOf("video") >= 0) {
intent.putExtra("type", 2)
} else {
intent.putExtra("type", 1)
}
}
switch (option.pageOrientation) {
case "auto": {
intent.putExtra("page_orientation", 2)
break
}
case "portrait": {
intent.putExtra("page_orientation", 1)
break
}
case "landscape": {
intent.putExtra("page_orientation", 0)
break
}
default: {
intent.putExtra("page_orientation", 1)
break
}
}
UTSAndroid.getUniActivity()!.startActivityForResult(intent, 10086)
} catch (e) {
var error = new ImageErrorImpl(2101010, "uni-chooseSystemMedia")
option.fail?.(error)
option.complete?.(error)
}
}
function __chooseSystemImage(option : ChooseSystemImageOptions) {
try {
resultCallback = (requestCode : Int, resultCode : Int, data : Intent | null) => {
UTSAndroid.offAppActivityResult(resultCallback!)
if (10086 == requestCode && resultCode == -1) {
if (data != null) {
var result = data!.getParcelableArrayExtra("paths")
if (result != null && result!.size > 0) {
var paths : Array<string> = []
result.forEach((p : Parcelable) => {
if (p instanceof Media)
if (UTSAndroid.isUniAppX()) {
paths.push("file://" + (p.path!))
} else {
if (p.type == 1) {
paths.push("file://" + copyResource(p.path!))
} else {
paths.push("file://" + (p.path!))
}
}
})
var success : ChooseSystemImageSuccessResult = {
filePaths: paths
...
...
@@ -99,12 +212,11 @@ var CACHEPATH = UTSAndroid.getAppCachePath()
function copyResource(url : string) : string {
var path : String = CACHEPATH!
if (CACHEPATH?.endsWith("/") == true) {
path = CACHEPATH + "
/uni-getSystemImage
/"
path = CACHEPATH + "
uni-getSystemMedia
/"
} else {
path = CACHEPATH + "/uni-getSystem
Image
/"
path = CACHEPATH + "/uni-getSystem
Media
/"
}
path = path + new File(url).getName()
console.log(path)
copyFile(url, path)
return path
}
...
...
uni_modules/uni-chooseSystemImage/utssdk/app-android/libs/chooseMedia-release.aar
浏览文件 @
e02013bb
无法预览此类型文件
uni_modules/uni-chooseSystemImage/utssdk/interface.uts
浏览文件 @
e02013bb
...
...
@@ -17,4 +17,22 @@ export type ChooseSystemImageOptions = {
complete ?: ChooseSystemImageCompleteCallback | null
}
export type ChooseSystemImage = (options : ChooseSystemImageOptions) => void
\ No newline at end of file
export type ChooseSystemImage = (options : ChooseSystemImageOptions) => void
export type ChooseSystemMediaSuccessResult = {
filePaths : Array<string>
}
export type ChooseSystemMediaSuccessCallback = (result : ChooseSystemMediaSuccessResult) => void
export type ChooseSystemMediaFailResult = ChooseSystemImageError
export type ChooseSystemMediaFailCallback = (result : ChooseSystemMediaFailResult) => void
export type ChooseSystemMediaCompleteCallback = (callback : any) => void
export type ChooseSystemMediaOptions = {
count : number,
mediaType ?: Array<string> | null,
pageOrientation ?: string | null,
success ?: ChooseSystemMediaSuccessCallback | null,
fail ?: ChooseSystemMediaFailCallback | null,
complete ?: ChooseSystemMediaCompleteCallback | null
}
export type ChooseSystemMedia = (options : ChooseSystemMediaOptions) => void
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录