react-native-callkeep
react-native-callkeep copied to clipboard
Android 11 Permission request phone calling account
Bug report
- [ x] I've checked the example to reproduce the issue.
Description
I tried to do the same with your example. But when my app starts and initializes react-native-callkeep, Android 11 always shows the pop-up to ask the permissions. I used Samsung Galaxy A12 with android version 11.
Versions
- Callkeep: 4.3.1
Hello @huyhpham: I am also facing the same issue with my Samsung Galaxy A21s, with Android 11. Let me know once you able to fix this?
Any update ? Does anyone has any solution ?
Hi guys, This is my solution for now: I fork to new project and add one more variable to turn off the asking permissions popup.
@huynextlevel could you please elaborate? what variable did you add? I can't find the fork in your repositories list. Does your fix persist the "calling accounts" permission?
Here is my solution @armouti. I added a variable isHideAlert
in the options
param. In the file index.js of react-native-callkeep library at function _setupAndroid
I fix like image below. For asking the permissions I will use react-native-permission library.
@huynextlevel Thanks for your prompt response. But I think the issue I'm having is the phoneAccount (Calling Accounts) persisting. For some reason on samsung, it seems to keep toggling back off even after the user toggles it on. The user has to toggle on "calling accounts" (which corresponds to registerPhoneAccount) multiple times before that persists. Have you had any issues with that?
@huynextlevel Thanks for your prompt response. But I think the issue I'm having is the phoneAccount (Calling Accounts) persisting. For some reason on samsung, it seems to keep toggling back off even after the user toggles it on. The user has to toggle on "calling accounts" (which corresponds to registerPhoneAccount) multiple times before that persists. Have you had any issues with that?
@armouti I have the exact same issue on Samsung phones. All other phones work fine. I'm looking for a fix aswell. Did you happen to find one?
@swcloud1 I didn't actually, I worked my way around it by creating a way in the app to force users to keep toggling the phone accounts back on until it persisted.
I used the method hasDefaultPhoneAccount to prompt the user to get go back and toggle it again if it's off.
I also used the lib patch-package
to add the argument "cancelable" to that method so that the user is unable to continue forward with using the app unless their toggle has persisted. Terrible UX i know but that's the best fix I came up with using this library. please let me know if you figure something better out
export default async function ensurePhoneAccountEnabledAndroid() {
if (isAndroid) {
try {
const phoneAccountEnabled = await RNCallKeep.hasPhoneAccount();
console.log({ phoneAccountEnabled })
if (!phoneAccountEnabled) {
//@ts-ignore wrong ts type by library
RNCallKeep.hasDefaultPhoneAccount({
alertTitle: 'Permission setting failed - please press okay to try again',
alertDescription: 'Please press ok to give permission again. Please be patient, you might have to do this many times until it works, but once it works it will never happen again. We apologize for the inconvenience',
cancelable: false
})
}
} catch (error) {
logError(error, 'ensurePhoneAccountAndroid');
showErrorToast('Permission error', 'Unable to set calling permission');
}
}
}
Based on @armouti solution, I optimized the workflow a little by calling NativeModules.RNCallKeep.openPhoneAccounts
instead of RNCallKeep.hasPhoneAccount()
. As such we can skip a least a step for the user.
I have also made it so that the app checks for the permissions automatically upon returning to the foreground such that we get a more optimized flow of check and retry.
// Workaround for Samsung devices not properly registering telecom
// services permissions.
if (Platform.OS == "android") {
let currentAppState = "active"
let appStateChangeListener = async (nextAppState: any) => {
if (currentAppState === "background" && nextAppState === "active") {
let hasPhoneAccount = await RNCallKeep.hasPhoneAccount()
if (hasPhoneAccount) return
const alertTitle = "Permission setting failed"
const alertDescription =
"We have detected that our application has not been granted the proper telecommunication service access rights.\n\nSome Android devices present a malfunction forcing you to have to set permissions multiple times before they are properly saved.\n\nPlease try again."
const tryAgainButton = {
text: "Try Again",
onPress: () => NativeModules.RNCallKeep.openPhoneAccounts(),
}
Alert.alert(alertTitle, alertDescription, [tryAgainButton])
}
currentAppState = nextAppState
}
AppState.addEventListener("change", appStateChangeListener)
}
That being said, do we have any hope of Samsung fixing this? I looked quickly but I am not sure where to report such a bug.
edit: I found this https://stackoverflow.com/questions/4928267/where-to-report-device-specific-bugs-to-samsung
Based on what I've seen with apps like Whatsapp and Skype, the major apps don't use phone accounts at all. I ended up using the self managed mode to show a local persistant calling notification, but you could also use a fullscreen overlay over the lockscreen to handle the call.
@swcloud1 I haven't played with the self-managed mode yet. Do I understand correctly that with it we can even show screens on top of the lock-screen?
@glesperance yes. by turning it on and adding some permissions and flags, you will be able to. Mind you it can get a bit complex as you'll have to manage multiple activities for it to work on all devices correctly.
@swcloud1 interesting. Do you have any documentation, article, GitHub repos, or examples to refer me to other than the Build A Calling App[1] mentioned in the RNCallkeep docs?
[1] https://developer.android.com/guide/topics/connectivity/telecom/selfManaged
@glesperance I ended up forking react-native-push-notification and changing the code to implement some of the changes I found in this fork: https://www.npmjs.com/package/react-native-push-notification-full-screen-intent . Besides then you need to change you MainActivity and set some extra parameters. I cant find the exact ones but the initial post in this thread is a good start. https://stackoverflow.com/q/60876523 . There are better explanations out there that tie everything together, but this is a good place to start.
Thank you @swcloud1! That a good start indeed :)