fix: 解决荣耀手机由于没有文件写入权限导致无法拍照问题
parent
a87afded86
commit
4991005a8e
|
|
@ -7,7 +7,7 @@ module.exports = async function (ctx) {
|
|||
gradleFiles.map((f)=>{
|
||||
let data = fs.readFileSync(f, 'utf-8')
|
||||
if(data.indexOf('https://maven.google.com')>=0){
|
||||
data = data.replace(/https\:\/\/maven\.google\.com/g,'http://maven.aliyun.com/nexus/content/groups/public/')
|
||||
data = data.replace(/https\:\/\/maven\.google\.com/g,'https://maven.aliyun.com/nexus/content/groups/public/')
|
||||
fs.writeFileSync(f,data)
|
||||
}
|
||||
})
|
||||
|
|
@ -19,4 +19,4 @@ module.exports = async function (ctx) {
|
|||
}
|
||||
|
||||
console.log("======修改 build.gradle mirror")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<widget android-packageName="seller.yunduoxd.com" defaultlocale="zh_CN" id="com.pingco.yunduoxd" version="0.0.14" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:tools="http://schemas.android.com/tools">
|
||||
<widget android-packageName="seller.yunduoxd.com" defaultlocale="zh_CN" id="com.pingco.yunduoxd" version="0.0.15" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:tools="http://schemas.android.com/tools">
|
||||
<name>云朵小店</name>
|
||||
<description>云朵小店店主端</description>
|
||||
<author email="dev@cordova.apache.org" href="https://cordova.apache.org">
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
<feature name="StatusBar">
|
||||
<param name="ios-package" onload="true" value="CDVStatusBar" />
|
||||
</feature>
|
||||
<preference name="AppendUserAgent" value="DaxiangzjSeller/0.0.14" />
|
||||
<preference name="AppendUserAgent" value="DaxiangzjSeller/0.0.15" />
|
||||
<platform name="android">
|
||||
<preference name="android-build-tool" value="gradle" />
|
||||
<config-file parent="/*" target="AndroidManifest.xml">
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -16,6 +16,7 @@
|
|||
"cordova-android": "^12.0.0",
|
||||
"cordova-ios": "^6.3.0",
|
||||
"cordova-plugin-cache": "file:../cordova_plugins/cordova-plugin-cache",
|
||||
"cordova-plugin-camera": "^7.0.0",
|
||||
"cordova-plugin-splashscreen": "^6.0.1",
|
||||
"cordova-plugin-statusbar": "3.0.0"
|
||||
},
|
||||
|
|
@ -25,9 +26,7 @@
|
|||
"ios"
|
||||
],
|
||||
"plugins": {
|
||||
"cordova-plugin-camera": {
|
||||
"ANDROIDX_CORE_VERSION": "1.6.0"
|
||||
},
|
||||
"cordova-plugin-camera": {},
|
||||
"cordova-plugin-vibration": {},
|
||||
"cordova-open-native-settings": {},
|
||||
"cordova-plugin-dialogs": {},
|
||||
|
|
@ -55,7 +54,6 @@
|
|||
"cordova-plugin-appversion": "1.0.0",
|
||||
"cordova-plugin-background-mode": "0.7.3",
|
||||
"cordova-plugin-badge": "0.8.9",
|
||||
"cordova-plugin-camera": "6.0.0",
|
||||
"cordova-plugin-device": "2.1.0",
|
||||
"cordova-plugin-dialogs": "2.0.2",
|
||||
"cordova-plugin-file": "7.0.0",
|
||||
|
|
|
|||
|
|
@ -113,6 +113,55 @@ function showPermissionDialog(msg) {
|
|||
openAppSetting();
|
||||
});
|
||||
}
|
||||
|
||||
// 拍照
|
||||
function takePicture() {
|
||||
return new Promise((resolve, reject) => {
|
||||
navigator.camera.getPicture(
|
||||
(base64Data) => {
|
||||
resolve(base64ToBlob(base64Data));
|
||||
},
|
||||
(err) => {
|
||||
// 如果失败
|
||||
console.warn("Could not access device camera.", err);
|
||||
|
||||
if (err == "has no access to camera" || err == 20) {
|
||||
// 没有权限,弹出提示
|
||||
reject(new Error(`您已拒绝应用访问相机(${err})`));
|
||||
return;
|
||||
}
|
||||
reject(new Error(err));
|
||||
},
|
||||
{
|
||||
// 相机选项
|
||||
sourceType: Camera.PictureSourceType.CAMERA,
|
||||
encodingType: Camera.EncodingType.JPEG,
|
||||
destinationType: Camera.DestinationType.DATA_URL,
|
||||
quality: 50,
|
||||
correctOrientation: true,
|
||||
targetWidth: 700,
|
||||
targetHeight: 700
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
function base64ToBlob(base64Data) {
|
||||
// 将base64的数据部分提取出来
|
||||
const contentType = 'image/jpeg';
|
||||
const raw = window.atob(base64Data);
|
||||
// 将原始数据转换为Uint8Array
|
||||
const rawLength = raw.length;
|
||||
const uInt8Array = new Uint8Array(rawLength);
|
||||
for (let i = 0; i < rawLength; ++i) {
|
||||
uInt8Array[i] = raw.charCodeAt(i);
|
||||
}
|
||||
|
||||
// 使用Uint8Array创建Blob,然后使用Blob创建File对象
|
||||
const blob = new Blob([uInt8Array], {type: contentType});
|
||||
blob.name = "image.jpeg";
|
||||
return blob;
|
||||
}
|
||||
|
||||
export function captureImage(sourceType) {
|
||||
return new Promise((resolve, reject) => {
|
||||
requestPermissions(
|
||||
|
|
@ -132,7 +181,7 @@ export function captureImage(sourceType) {
|
|||
// this.$q.notify({message:e.message,timeout:0,actions: [
|
||||
// { label: 'OK', handler: () => { } }
|
||||
// ]});
|
||||
reject(err);
|
||||
reject(e);
|
||||
});
|
||||
},
|
||||
(err) => {
|
||||
|
|
@ -158,6 +207,14 @@ export function captureImage(sourceType) {
|
|||
);
|
||||
},
|
||||
(err) => {
|
||||
if(err.permission == "WRITE_EXTERNAL_STORAGE") {
|
||||
// vivo、华为荣耀手机等,无法设置写入权限
|
||||
takePicture().then(resolve).catch(err => {
|
||||
showPermissionDialog(err.message);
|
||||
reject(err);
|
||||
})
|
||||
return
|
||||
}
|
||||
showPermissionDialog(
|
||||
err.permission == "CAMERA"
|
||||
? "您已拒绝应用使用摄像头权限"
|
||||
|
|
|
|||
Loading…
Reference in New Issue