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

View File

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

View File

@ -105,42 +105,9 @@ export default struct Index {
this.appInactiveState = false; this.appInactiveState = false;
this.notificationManager.cancelNotification(); this.notificationManager.cancelNotification();
this.notificationManager.sendCapsuleNotification(this.callData, false); this.notificationManager.sendCapsuleNotification(this.callData, false);
this.initPermissions()
HiLog.i(TAG, "onPageShow end : ") 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() { onPageHide() {
HiLog.i(TAG, "onPageHide :") HiLog.i(TAG, "onPageHide :")
this.appInactiveState = true; this.appInactiveState = true;