Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
e02013bb
U
uni-api
项目概览
DCloud
/
uni-api
通知
670
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"
,
"id"
:
"uni-chooseSystemImage"
,
"displayName"
:
"uni-chooseSystem
Image
"
,
"displayName"
:
"uni-chooseSystem
Media
"
,
"version"
:
"1.
0
.0"
,
"version"
:
"1.
1
.0"
,
"description"
:
"
uni-chooseSystemImage
"
,
"description"
:
"
从手机相册中选择图片或视频,解决google play新政策禁止添加媒体权限的问题
"
,
"keywords"
:
[
"keywords"
:
[
"uni-chooseSystemImage"
"google"
,
"上架"
,
"图片选择"
],
],
"repository"
:
""
,
"repository"
:
""
,
"engines"
:
{
"engines"
:
{
"HBuilderX"
:
"^
3.6.8
"
"HBuilderX"
:
"^
4.29
"
},
},
"dcloudext"
:
{
"dcloudext"
:
{
"type"
:
"uts"
,
"type"
:
"uts"
,
...
@@ -24,9 +26,9 @@
...
@@ -24,9 +26,9 @@
"qq"
:
""
"qq"
:
""
},
},
"declaration"
:
{
"declaration"
:
{
"ads"
:
""
,
"ads"
:
"
无
"
,
"data"
:
""
,
"data"
:
"
本插件不会采集任何隐私信息,获取权限仅是为了兼容android12及以下版本的系统。
"
,
"permissions"
:
""
"permissions"
:
"
<uses-permission android:name=
\"
android.permission.READ_EXTERNAL_STORAGE
\"
/>
"
},
},
"npmurl"
:
""
"npmurl"
:
""
},
},
...
@@ -35,47 +37,47 @@
...
@@ -35,47 +37,47 @@
"encrypt"
:
[],
"encrypt"
:
[],
"platforms"
:
{
"platforms"
:
{
"cloud"
:
{
"cloud"
:
{
"tcb"
:
"
u
"
,
"tcb"
:
"
y
"
,
"aliyun"
:
"
u
"
,
"aliyun"
:
"
y
"
,
"alipay"
:
"
u
"
"alipay"
:
"
y
"
},
},
"client"
:
{
"client"
:
{
"Vue"
:
{
"Vue"
:
{
"vue2"
:
"
u
"
,
"vue2"
:
"
n
"
,
"vue3"
:
"
u
"
"vue3"
:
"
n
"
},
},
"App"
:
{
"App"
:
{
"app-android"
:
"u"
,
"app-android"
:
"u"
,
"app-ios"
:
"u
"
,
"app-ios"
:
"n
"
,
"app-harmony"
:
"u
"
"app-harmony"
:
"n
"
},
},
"H5-mobile"
:
{
"H5-mobile"
:
{
"Safari"
:
"
u
"
,
"Safari"
:
"
n
"
,
"Android Browser"
:
"
u
"
,
"Android Browser"
:
"
n
"
,
"微信浏览器(Android)"
:
"
u
"
,
"微信浏览器(Android)"
:
"
n
"
,
"QQ浏览器(Android)"
:
"
u
"
"QQ浏览器(Android)"
:
"
n
"
},
},
"H5-pc"
:
{
"H5-pc"
:
{
"Chrome"
:
"
u
"
,
"Chrome"
:
"
n
"
,
"IE"
:
"
u
"
,
"IE"
:
"
n
"
,
"Edge"
:
"
u
"
,
"Edge"
:
"
n
"
,
"Firefox"
:
"
u
"
,
"Firefox"
:
"
n
"
,
"Safari"
:
"
u
"
"Safari"
:
"
n
"
},
},
"小程序"
:
{
"小程序"
:
{
"微信"
:
"
u
"
,
"微信"
:
"
n
"
,
"阿里"
:
"
u
"
,
"阿里"
:
"
n
"
,
"百度"
:
"
u
"
,
"百度"
:
"
n
"
,
"字节跳动"
:
"
u
"
,
"字节跳动"
:
"
n
"
,
"QQ"
:
"
u
"
,
"QQ"
:
"
n
"
,
"钉钉"
:
"
u
"
,
"钉钉"
:
"
n
"
,
"快手"
:
"
u
"
,
"快手"
:
"
n
"
,
"飞书"
:
"
u
"
,
"飞书"
:
"
n
"
,
"京东"
:
"
u
"
"京东"
:
"
n
"
},
},
"快应用"
:
{
"快应用"
:
{
"华为"
:
"
u
"
,
"华为"
:
"
n
"
,
"联盟"
:
"
u
"
"联盟"
:
"
n
"
}
}
}
}
}
}
...
...
uni_modules/uni-chooseSystemImage/utssdk/app-android/index.uts
浏览文件 @
e02013bb
/* 引入 interface.uts 文件中定义的变量 */
/* 引入 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 AppCompatActivity from 'androidx.appcompat.app.AppCompatActivity';
import ActivityResultCallback from 'androidx.activity.result.ActivityResultCallback';
import ActivityResultCallback from 'androidx.activity.result.ActivityResultCallback';
import List from 'kotlin.collections.List';
import List from 'kotlin.collections.List';
...
@@ -23,6 +23,9 @@ import FileInputStream from 'java.io.FileInputStream';
...
@@ -23,6 +23,9 @@ import FileInputStream from 'java.io.FileInputStream';
import FileOutputStream from 'java.io.FileOutputStream';
import FileOutputStream from 'java.io.FileOutputStream';
import InputStream from 'java.io.InputStream';
import InputStream from 'java.io.InputStream';
import Build from 'android.os.Build';
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
var resultCallback : ((requestCode : Int, resultCode : Int, data ?: Intent) => void) | null = null
export const chooseSystemImage : ChooseSystemImage = function (option : ChooseSystemImageOptions) {
export const chooseSystemImage : ChooseSystemImage = function (option : ChooseSystemImageOptions) {
...
@@ -45,22 +48,132 @@ export const chooseSystemImage : ChooseSystemImage = function (option : ChooseSy
...
@@ -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 {
try {
resultCallback = (requestCode : Int, resultCode : Int, data : Intent | null) => {
resultCallback = (requestCode : Int, resultCode : Int, data : Intent | null) => {
UTSAndroid.offAppActivityResult(resultCallback!)
UTSAndroid.offAppActivityResult(resultCallback!)
if (10086 == requestCode && resultCode == -1) {
if (10086 == requestCode && resultCode == -1) {
if (data != null) {
if (data != null) {
var result = data!.get
String
ArrayExtra("paths")
var result = data!.get
Parcelable
ArrayExtra("paths")
if (result != null && result!.size > 0) {
if (result != null && result!.size > 0) {
var paths : Array<string> = []
var paths : Array<string> = []
result.forEach((p : string) => {
result.forEach((p : Parcelable) => {
if (p instanceof Media)
if (UTSAndroid.isUniAppX()) {
if (UTSAndroid.isUniAppX()) {
paths.push("file://" + (p
))
paths.push("file://" + (p.path!
))
} else {
} else {
paths.push("file://" + copyResource(p))
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 = {
var success : ChooseSystemImageSuccessResult = {
filePaths: paths
filePaths: paths
...
@@ -99,12 +212,11 @@ var CACHEPATH = UTSAndroid.getAppCachePath()
...
@@ -99,12 +212,11 @@ var CACHEPATH = UTSAndroid.getAppCachePath()
function copyResource(url : string) : string {
function copyResource(url : string) : string {
var path : String = CACHEPATH!
var path : String = CACHEPATH!
if (CACHEPATH?.endsWith("/") == true) {
if (CACHEPATH?.endsWith("/") == true) {
path = CACHEPATH + "
/uni-getSystemImage
/"
path = CACHEPATH + "
uni-getSystemMedia
/"
} else {
} else {
path = CACHEPATH + "/uni-getSystem
Image
/"
path = CACHEPATH + "/uni-getSystem
Media
/"
}
}
path = path + new File(url).getName()
path = path + new File(url).getName()
console.log(path)
copyFile(url, path)
copyFile(url, path)
return path
return path
}
}
...
...
uni_modules/uni-chooseSystemImage/utssdk/app-android/libs/chooseMedia-release.aar
浏览文件 @
e02013bb
无法预览此类型文件
uni_modules/uni-chooseSystemImage/utssdk/interface.uts
浏览文件 @
e02013bb
...
@@ -18,3 +18,21 @@ export type ChooseSystemImageOptions = {
...
@@ -18,3 +18,21 @@ export type ChooseSystemImageOptions = {
}
}
export type ChooseSystemImage = (options : ChooseSystemImageOptions) => void
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录