!27 权限初始化修改

Merge pull request !27 from 徐黔南/master
This commit is contained in:
openharmony_ci 2022-05-12 03:28:44 +00:00 committed by Gitee
commit c6f5686452
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 30 additions and 79 deletions

View File

@ -95,7 +95,6 @@ export default struct IncomingCom {
content = typeName
HiLog.i(TAG, "sendMessage resourceManager.getResourceManager : ");
return new Promise(function (resolve, reject) {
if (globalThis.sendPermissionFlag) {
sms.sendMessage({
slotId: slotId,
destinationHost: destinationHost,
@ -114,7 +113,6 @@ export default struct IncomingCom {
}
});
}
}
);
})
})
@ -164,7 +162,6 @@ export default struct IncomingCom {
let Err: string = "";
let Message: string = ""
this.sendMessage(obj)
if (globalThis.sendPermissionFlag) {
if (this.SendResult) {
resourceManager.getResourceManager().then(result => {
result.getString($r("app.string.SMS_Sent")
@ -189,17 +186,6 @@ export default struct IncomingCom {
})
})
}
} else {
resourceManager.getResourceManager().then(result => {
result.getString($r("app.string.SMS_Authorization_Notification").id, (err, typeName) => {
Message = typeName
prompt.showToast({
message: Message,
duration: 2000,
});
})
})
}
}
/**

View File

@ -128,9 +128,7 @@ export default class CallManager {
* @param { Object } callData -Object
*/
async update(callData) {
if (globalThis.permissionFlag) {
await this.contactManager.getContactInfo(callData)
}
this.mCallDataManager.update(callData);
call.formatPhoneNumber(callData.accountNumber, (err, data) => {
if (data === undefined) {

View File

@ -105,42 +105,9 @@ export default struct Index {
this.appInactiveState = false;
this.notificationManager.cancelNotification();
this.notificationManager.sendCapsuleNotification(this.callData, false);
this.initPermissions()
HiLog.i(TAG, "onPageShow end : ")
}
async initPermissions() {
let requestPermissions: Array<string> = ["ohos.permission.READ_CONTACTS", "ohos.permission.SEND_MESSAGES"];
HiLog.i(TAG, "initPermissions requestPermissions : " + requestPermissions.length)
if (requestPermissions.length > 0) {
let context = featureAbility.getContext()
context.requestPermissionsFromUser(requestPermissions, 2345, (results) => {
let data:any = results;
for (let i = 0;i < data.authResults.length; i++) {
if(data.permissions[i] === "ohos.permission.READ_CONTACTS"){
if (data.authResults[i] === 0) {
globalThis.permissionFlag = true
globalThis.callManager.update(this.callData)
} else {
globalThis.permissionFlag = false
globalThis.sendPermissionFlag = true
}
}
if(data.permissions[i] === "ohos.permission.SEND_MESSAGES"){
if (data.authResults[i] === 0) {
globalThis.sendPermissionFlag = true
} else {
globalThis.permissionFlag = true
globalThis.callManager.update(this.callData)
globalThis.sendPermissionFlag = false
}
}
}
})
}
HiLog.i(TAG, "Application requestPermissionsFromUser end")
}
onPageHide() {
HiLog.i(TAG, "onPageHide :")
this.appInactiveState = true;