Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
c93683eb
U
uni-api
项目概览
DCloud
/
uni-api
通知
689
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看板
提交
c93683eb
编写于
10月 23, 2024
作者:
张
张磊
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
支持通过api调用系统图片选择,解决上架google play问题
上级
6428fb49
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
295 addition
and
0 deletion
+295
-0
uni_modules/uni-chooseSystemImage/changelog.md
uni_modules/uni-chooseSystemImage/changelog.md
+0
-0
uni_modules/uni-chooseSystemImage/package.json
uni_modules/uni-chooseSystemImage/package.json
+83
-0
uni_modules/uni-chooseSystemImage/readme.md
uni_modules/uni-chooseSystemImage/readme.md
+7
-0
uni_modules/uni-chooseSystemImage/utssdk/app-android/config.json
...ules/uni-chooseSystemImage/utssdk/app-android/config.json
+7
-0
uni_modules/uni-chooseSystemImage/utssdk/app-android/index.uts
...odules/uni-chooseSystemImage/utssdk/app-android/index.uts
+153
-0
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
+20
-0
uni_modules/uni-chooseSystemImage/utssdk/unierror.uts
uni_modules/uni-chooseSystemImage/utssdk/unierror.uts
+25
-0
未找到文件。
uni_modules/uni-chooseSystemImage/changelog.md
0 → 100644
浏览文件 @
c93683eb
uni_modules/uni-chooseSystemImage/package.json
0 → 100644
浏览文件 @
c93683eb
{
"id"
:
"uni-chooseSystemImage"
,
"displayName"
:
"uni-chooseSystemImage"
,
"version"
:
"1.0.0"
,
"description"
:
"uni-chooseSystemImage"
,
"keywords"
:
[
"uni-chooseSystemImage"
],
"repository"
:
""
,
"engines"
:
{
"HBuilderX"
:
"^3.6.8"
},
"dcloudext"
:
{
"type"
:
"uts"
,
"sale"
:
{
"regular"
:
{
"price"
:
"0.00"
},
"sourcecode"
:
{
"price"
:
"0.00"
}
},
"contact"
:
{
"qq"
:
""
},
"declaration"
:
{
"ads"
:
""
,
"data"
:
""
,
"permissions"
:
""
},
"npmurl"
:
""
},
"uni_modules"
:
{
"dependencies"
:
[],
"encrypt"
:
[],
"platforms"
:
{
"cloud"
:
{
"tcb"
:
"u"
,
"aliyun"
:
"u"
,
"alipay"
:
"u"
},
"client"
:
{
"Vue"
:
{
"vue2"
:
"u"
,
"vue3"
:
"u"
},
"App"
:
{
"app-android"
:
"u"
,
"app-ios"
:
"u"
,
"app-harmony"
:
"u"
},
"H5-mobile"
:
{
"Safari"
:
"u"
,
"Android Browser"
:
"u"
,
"微信浏览器(Android)"
:
"u"
,
"QQ浏览器(Android)"
:
"u"
},
"H5-pc"
:
{
"Chrome"
:
"u"
,
"IE"
:
"u"
,
"Edge"
:
"u"
,
"Firefox"
:
"u"
,
"Safari"
:
"u"
},
"小程序"
:
{
"微信"
:
"u"
,
"阿里"
:
"u"
,
"百度"
:
"u"
,
"字节跳动"
:
"u"
,
"QQ"
:
"u"
,
"钉钉"
:
"u"
,
"快手"
:
"u"
,
"飞书"
:
"u"
,
"京东"
:
"u"
},
"快应用"
:
{
"华为"
:
"u"
,
"联盟"
:
"u"
}
}
}
}
}
\ No newline at end of file
uni_modules/uni-chooseSystemImage/readme.md
0 → 100644
浏览文件 @
c93683eb
# uni-chooseSystemImage
### 开发文档
[
UTS 语法
](
https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html
)
[
UTS API插件
](
https://uniapp.dcloud.net.cn/plugin/uts-plugin.html
)
[
UTS uni-app兼容模式组件
](
https://uniapp.dcloud.net.cn/plugin/uts-component.html
)
[
UTS 标准模式组件
](
https://doc.dcloud.net.cn/uni-app-x/plugin/uts-vue-component.html
)
[
Hello UTS
](
https://gitcode.net/dcloud/hello-uts
)
uni_modules/uni-chooseSystemImage/utssdk/app-android/config.json
0 → 100644
浏览文件 @
c93683eb
{
"dependencies"
:
[
"androidx.appcompat:appcompat:1.6.1"
,
"androidx.activity:activity-ktx:1.9.2"
],
"minSdkVersion"
:
"21"
}
\ No newline at end of file
uni_modules/uni-chooseSystemImage/utssdk/app-android/index.uts
0 → 100644
浏览文件 @
c93683eb
/* 引入 interface.uts 文件中定义的变量 */
import { ChooseSystemImage, ChooseSystemImageOptions, ChooseSystemImageSuccessResult, 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';
import Uri from 'android.net.Uri';
import ActivityResultContracts from 'androidx.activity.result.contract.ActivityResultContracts';
import ActivityResultLauncher from 'androidx.activity.result.ActivityResultLauncher';
import PickVisualMediaRequest from "androidx.activity.result.PickVisualMediaRequest";
import Builder from "androidx.activity.result.PickVisualMediaRequest.Builder";
import Context from 'com.alibaba.fastjson.parser.deserializer.ASMDeserializerFactory.Context';
import MediaStore from 'android.provider.MediaStore';
import Activity from "android.app.Activity"
import Intent from 'android.content.Intent';
import ChooseSystemImageActivity from "uts.sdk.modules.uniChooseSystemImage.ChooseSystemImageActivity"
/* 引入 unierror.uts 文件中定义的变量 */
import { ImageErrorImpl } from '../unierror';
import ChooseVideoOptions from 'uts.sdk.modules.DCloudUniMedia.ChooseVideoOptions';
import BitmapFactory from 'android.graphics.BitmapFactory';
import File from 'java.io.File';
import FileInputStream from 'java.io.FileInputStream';
import FileOutputStream from 'java.io.FileOutputStream';
import InputStream from 'java.io.InputStream';
import Build from 'android.os.Build';
var resultCallback : ((requestCode : Int, resultCode : Int, data ?: Intent) => void) | null = null
export const chooseSystemImage : ChooseSystemImage = function (option : ChooseSystemImageOptions) {
if (option.count <= 0) {
var error = new ImageErrorImpl(2101002, "uni-chooseSystemImage")
option.fail?.(error)
option.complete?.(error)
return
}
if (Build.VERSION.SDK_INT > 32) {
__chooseSystemImage(option)
} else {
UTSAndroid.requestSystemPermission(UTSAndroid.getUniActivity()!, [android.Manifest.permission.READ_EXTERNAL_STORAGE], (a : boolean, b : string[]) => {
__chooseSystemImage(option)
}, (a : boolean, b : string[]) => {
var error = new ImageErrorImpl(2101005, "uni-chooseSystemImage")
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!.getStringArrayExtra("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))
}
})
var success : ChooseSystemImageSuccessResult = {
filePaths: paths
}
option.success?.(success)
option.complete?.(success)
} else {
var error = new ImageErrorImpl(2101001, "uni-chooseSystemImage")
option.fail?.(error)
option.complete?.(error)
}
} else {
var error = new ImageErrorImpl(2101001, "uni-chooseSystemImage")
option.fail?.(error)
option.complete?.(error)
}
} else {
var error = new ImageErrorImpl(2101001, "uni-chooseSystemImage")
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)
intent.putExtra("type", 1)
UTSAndroid.getUniActivity()!.startActivityForResult(intent, 10086)
} catch (e) {
var error = new ImageErrorImpl(2101010, "uni-chooseSystemImage")
option.fail?.(error)
option.complete?.(error)
}
}
var CACHEPATH = UTSAndroid.getAppCachePath()
function copyResource(url : string) : string {
var path : String = CACHEPATH!
if (CACHEPATH?.endsWith("/") == true) {
path = CACHEPATH + "/uni-getSystemImage/"
} else {
path = CACHEPATH + "/uni-getSystemImage/"
}
path = path + new File(url).getName()
console.log(path)
copyFile(url, path)
return path
}
function copyFile(fromFilePath : string, toFilePath : string) : boolean {
var fis : InputStream | null = null
try {
let fromFile = new File(fromFilePath)
if (!fromFile.exists()) {
return false;
}
if (!fromFile.isFile()) {
return false
}
if (!fromFile.canRead()) {
return false;
}
fis = new FileInputStream(fromFile);
if (fis == null) {
return false
}
} catch (e) {
return false;
}
let toFile = new File(toFilePath)
if (!toFile.getParentFile().exists()) {
toFile.getParentFile().mkdirs()
}
if (!toFile.exists()) {
toFile.createNewFile()
}
try {
let fos = new FileOutputStream(toFile)
let byteArrays = ByteArray(1024)
var c = fis!!.read(byteArrays)
while (c > 0) {
fos.write(byteArrays, 0, c)
c = fis!!.read(byteArrays)
}
fis!!.close()
fos.close()
return true
} catch (e) {
return false;
}
}
\ No newline at end of file
uni_modules/uni-chooseSystemImage/utssdk/app-android/libs/chooseMedia-release.aar
0 → 100644
浏览文件 @
c93683eb
文件已添加
uni_modules/uni-chooseSystemImage/utssdk/interface.uts
0 → 100644
浏览文件 @
c93683eb
export type ChooseSystemImageSuccessResult = {
filePaths : Array<string>
}
export type ImageErrorCode = 2101001 | 2101010 | 2101002
export interface ChooseSystemImageError extends IUniError {
errCode : ImageErrorCode
};
export type ChooseSystemImageSuccessCallback = (result : ChooseSystemImageSuccessResult) => void
export type ChooseSystemImageFailResult = ChooseSystemImageError
export type ChooseSystemImageFailCallback = (result : ChooseSystemImageFailResult) => void
export type ChooseSystemImageCompleteCallback = (callback : any) => void
export type ChooseSystemImageOptions = {
count : number,
success ?: ChooseSystemImageSuccessCallback | null,
fail ?: ChooseSystemImageFailCallback | null,
complete ?: ChooseSystemImageCompleteCallback | null
}
export type ChooseSystemImage = (options : ChooseSystemImageOptions) => void
\ No newline at end of file
uni_modules/uni-chooseSystemImage/utssdk/unierror.uts
0 → 100644
浏览文件 @
c93683eb
import { ImageErrorCode, ChooseSystemImageError } from "./interface.uts"
export const ImageUniErrors : Map<number, string> = new Map([
/**
* 用户取消
*/
[2101001, 'user cancel'],
[2101002, 'fail parameter error'],
[2101005, "No Permission"],
/**
* 其他错误
*/
[2101010, "unexpect error:"]
]);
export class ImageErrorImpl extends UniError implements ChooseSystemImageError {
// #ifdef APP-ANDROID
override errCode : ImageErrorCode
// #endif
constructor(errCode : ImageErrorCode, uniErrorSubject : string) {
super()
this.errSubject = uniErrorSubject
this.errCode = errCode
this.errMsg = ImageUniErrors.get(errCode) ?? "";
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录