diff --git a/uni_modules/uni-chooseSystemImage/changelog.md b/uni_modules/uni-chooseSystemImage/changelog.md
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..6ff081a5fcc1ce55972c2ba6dd0521df35db7f0a 100644
--- a/uni_modules/uni-chooseSystemImage/changelog.md
+++ b/uni_modules/uni-chooseSystemImage/changelog.md
@@ -0,0 +1,4 @@
+## 1.1.0(2024-10-31)
+新增chooseSystemMedia,支持选择图片和视频。
+## 1.0.0(2024-10-23)
+新增插件
diff --git a/uni_modules/uni-chooseSystemImage/package.json b/uni_modules/uni-chooseSystemImage/package.json
index c71e97abbfcc2407f4906a2f9ae0530ebf242bab..2d4bf81e14337ae772e6b10a53baf7e328ca075b 100644
--- a/uni_modules/uni-chooseSystemImage/package.json
+++ b/uni_modules/uni-chooseSystemImage/package.json
@@ -1,14 +1,16 @@
{
"id": "uni-chooseSystemImage",
- "displayName": "uni-chooseSystemImage",
- "version": "1.0.0",
- "description": "uni-chooseSystemImage",
+ "displayName": "uni-chooseSystemMedia",
+ "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": ""
},
"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"
}
}
}
diff --git a/uni_modules/uni-chooseSystemImage/utssdk/app-android/index.uts b/uni_modules/uni-chooseSystemImage/utssdk/app-android/index.uts
index c3bd13d95fe65486885a34be50401e1ee2cedaf3..a1bd5cd40904595f9584fd9a0f944d2003f0b319 100644
--- a/uni_modules/uni-chooseSystemImage/utssdk/app-android/index.uts
+++ b/uni_modules/uni-chooseSystemImage/utssdk/app-android/index.uts
@@ -1,5 +1,5 @@
/* 引入 interface.uts 文件中定义的变量 */
-import { ChooseSystemImage, ChooseSystemImageOptions, ChooseSystemImageSuccessResult, ChooseSystemVideo, ChooseSystemVideoOptions, ChooseSystemVideoSuccessResult } from '../interface.uts';
+import { ChooseSystemImage, ChooseSystemImageOptions, ChooseSystemImageSuccessResult, ChooseSystemMedia, ChooseSystemMediaOptions, ChooseSystemMediaSuccessResult, ChooseSystemVideo, 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!.getStringArrayExtra("paths")
+ var result = data!.getParcelableArrayExtra("paths")
if (result != null && result!.size > 0) {
var paths : Array = []
- 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 = []
+ 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-getSystemImage/"
+ path = CACHEPATH + "/uni-getSystemMedia/"
}
path = path + new File(url).getName()
- console.log(path)
copyFile(url, path)
return path
}
diff --git a/uni_modules/uni-chooseSystemImage/utssdk/app-android/libs/chooseMedia-release.aar b/uni_modules/uni-chooseSystemImage/utssdk/app-android/libs/chooseMedia-release.aar
index 38d912b74fe598b64ae89c2bc79ab64d97d949d9..8dcbc30b2a60678d635c5a9c8e78423a16cd10d7 100644
Binary files a/uni_modules/uni-chooseSystemImage/utssdk/app-android/libs/chooseMedia-release.aar and b/uni_modules/uni-chooseSystemImage/utssdk/app-android/libs/chooseMedia-release.aar differ
diff --git a/uni_modules/uni-chooseSystemImage/utssdk/interface.uts b/uni_modules/uni-chooseSystemImage/utssdk/interface.uts
index dad094ae5527fe2a046a89732a989491820d4876..f8e388aa60ede34c625e3986c31c8e6cf9787d7c 100644
--- a/uni_modules/uni-chooseSystemImage/utssdk/interface.uts
+++ b/uni_modules/uni-chooseSystemImage/utssdk/interface.uts
@@ -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
+}
+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 | 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