Closed alorma closed 2 years ago
It also happens when denying permission.
I run this library on app made with compose
Repo example: https://github.com/alorma/TemporalContacts
I'll look into this possibly tomorrow. One thing I can say now is that this looks like it is caused by the permissions
module code; queryWithPermission()
and/or insertWithPermission()
. I wrote the permissions extensions using Dexter; https://github.com/Karumi/Dexter, which might not fully work with coroutines and/or Jetpack compose.
So, what you can do if you don't want to wait for me to fix this issue is to handle permissions yourself without using the permissions
extensions in this lib.
Unrelated to the crash, I noticed that you can reduce the lines of code in your app.
So instead of,
val rawContact = NewRawContact().apply {
setName { displayName = name }
if (phone != null) {
addPhone {
number = phone
type = PhoneEntity.Type.OTHER
}
}
if (email != null) {
addEmail {
address = email
type = EmailEntity.Type.OTHER
}
}
}
You can just do,
val rawContact = NewRawContact().apply {
setName { displayName = name }
addPhone {
number = phone
type = PhoneEntity.Type.OTHER
}
addEmail {
address = email
type = EmailEntity.Type.OTHER
}
}
You don't need the null checks. All data entity properties (i.e. number
, type
, address
) are nullable. If the important data (i.e. the phone number
, email address
) are null or blank, the insert
APIs will ignore it and it will NOT be inserted into the database. You can read more about this in How do I learn more about "blank" data?.
One more question. Do you have the developer option "Don't keep activities" enabled? I'm not saying that the crash should happen because of it but It will help me debug the issue 😄
Uhmmm, no, i had it disabled.
As well, my project is a single activity
I successfully created contact using allowBlanks(true)
and requesting permissions READ, WRITE and GET_ACCOUNTS
Cool! Two questions;
insertWithPermission
?allowBlanks(true)
?NO, I not used insertWithPermission()
, as I managed. permissions on other way
It works without allowBlanks(true)
yes
Thanks! I'll try to reproduce this on your temporal contacts app tomorrow. Do you have a branch or commit that still uses insertWithPermission()
that the happens in?
main branch commit: 5a7f9f0177572c4300c54e97a8a15b9eb76a1d34
I haven't had the chance to investigate this yet as I have been focusing on other things and this is not happening in the sample app. It is also not part of the core
module so the urgency is a little lower IMO. Most folks probably use different permissions libraries anyways. The extensions provided in the permissions
module are optional. That does NOT mean that I don't care about this!! This is scheduled to be included in the v0.2.1 Release so I am planning to work on it soon-ish 😁
Anyways, I'll add a help wanted sign in case someone else wants to take a look at this sooner.
Note to self. I was able to reproduce this same exact stack trace on the sample app by declining permissions on a Samsung Galaxy A71 running Android 11.
Migrating away from dexter may or may not solve this issue. Regardless, the migration away from dexter should occur before attempting to fix this bug. The bug might just go away after the migration.
So, this should not be worked on until #101 is done.
I verified that switching from Dexter to TedPermission does the trick! I can no longer reproduce the issue!
This will be resolved in scope of #101 😁
No breaking changes for library users!
CODES77
Code example:
When running an insert after, done after
queryWithPermission()
it crashes the app with the below stacktrace.Stacktrace: