!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,25 +95,23 @@ 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,
content: content,
sendCallback: (err, sendResult) => {
this.SendResult = sendResult
if (err) {
reject(err);
sms.sendMessage({
slotId: slotId,
destinationHost: destinationHost,
content: content,
sendCallback: (err, sendResult) => {
this.SendResult = sendResult
if (err) {
reject(err);
} else {
if (sendResult.result === SEND_SMS_SUCCESS) {
resolve(true);
} else {
if (sendResult.result === SEND_SMS_SUCCESS) {
resolve(true);
} else {
resolve(false);
}
resolve(false);
}
}
});
}
}
});
}
);
})
@ -164,37 +162,25 @@ 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")
.id, (err, typeName) => {
Content = typeName
prompt.showToast({
message: this.callData.contactName ? Content + `${this.callData.contactName}` : Content + `${this.callData.accountNumber}`,
duration: 2000,
});
this.mCallServiceProxy.rejectCall(this.callData.callId, obj.msg);
HiLog.i(TAG, "msgItemClick : ");
})
if (this.SendResult) {
resourceManager.getResourceManager().then(result => {
result.getString($r("app.string.SMS_Sent")
.id, (err, typeName) => {
Content = typeName
prompt.showToast({
message: this.callData.contactName ? Content + `${this.callData.contactName}` : Content + `${this.callData.accountNumber}`,
duration: 2000,
});
this.mCallServiceProxy.rejectCall(this.callData.callId, obj.msg);
HiLog.i(TAG, "msgItemClick : ");
})
} else {
resourceManager.getResourceManager().then(result => {
result.getString($r("app.string.message_Failed").id, (err, typeName) => {
Err = typeName
prompt.showToast({
message: Err,
duration: 2000,
});
})
})
}
})
} else {
resourceManager.getResourceManager().then(result => {
result.getString($r("app.string.SMS_Authorization_Notification").id, (err, typeName) => {
Message = typeName
result.getString($r("app.string.message_Failed").id, (err, typeName) => {
Err = typeName
prompt.showToast({
message: Message,
message: Err,
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)
}
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;