Jul 31 | 8:55 AM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Jul 31 | 9:15 AM |
trocchietto_Ivano | has entered the room |
trocchietto_Ivano |
Good morning Mark!
|
Jul 31 | 9:20 AM |
trocchietto_Ivano |
hello
|
trocchietto_Ivano |
View paste
|
Jul 31 | 9:30 AM |
Mark M. |
sorry! I lost track of this window!
|
Mark M. |
I have not worked much with CalendarContract, beyond what is in the book
|
Jul 31 | 9:35 AM |
trocchietto_Ivano |
ok
|
Mark M. |
when you say "the event is not registered in my calendar at all", what do you mean?
|
trocchietto_Ivano |
that I am deploying the small prototype app on my samsung
|
trocchietto_Ivano |
and although I do not have any error, and the flow is correct according to the debug, after I launch contentprovider.insert, I do not get any result
|
trocchietto_Ivano |
what can go wrong is 1)contentProvider.Insert is not enough to insert an event to the Calendar 2) I have multiple accounts and does not work 3) gmail needs a special oauth
|
Mark M. |
what do you mean by "I do not get any result"? do you mean that the local calendar app is not showing the event? do you mean that the event is not being synchronized to the server? do you mean something else?
|
trocchietto_Ivano |
and most important maybe I did not put the method in the right place, because of the permissions
|
trocchietto_Ivano |
I mean the local calendar( the one I have on my phone with 3 gmail accounts) do not show the event
|
Mark M. |
is this the official Google Calendar app, or is it some Samsung replacement?
|
Jul 31 | 9:40 AM |
trocchietto_Ivano |
I tried the samsung replacement but also the google default app(where also are registered 3 gmail accounts)
|
Mark M. |
have you tried querying the provider using a ContentResolver, to see if you can find your event that way? if that fails, then there is some problem with the insert itself -- if that succeeds, though, that suggests that something is out of sync between the event data and what the apps are trying to show
|
trocchietto_Ivano |
this is a good idea, but looks really not pratical to me to insert a query, but is a reasonable way to go
|
trocchietto_Ivano |
to see if the event is registered in the db by the calendar content provider!
|
trocchietto_Ivano |
but can i ask you about permissions
|
trocchietto_Ivano |
basically when the ide(android studio) say me that I need to register the permissions to READ_CALENDAR
|
trocchietto_Ivano |
I do not put nothing in the call back onResult
|
trocchietto_Ivano |
but the command is passed directly into the method where I have everything
|
trocchietto_Ivano |
so I guess maybe I miss something with permissions
|
Mark M. |
for insert(), you should need WRITE_CALENDAR, though I would expect a SecurityException if you do not hold that
|
trocchietto_Ivano |
exaclty
|
trocchietto_Ivano |
that is why the system set up all the marshmellow thing
|
Jul 31 | 9:45 AM |
trocchietto_Ivano |
the manifest check, the rationale and the insert that will trigger the onResult call back
|
trocchietto_Ivano |
my question is should I put some command into the onResult switch case Tag related to write calendar? because I did not put any command in the callback
|
trocchietto_Ivano |
(hope is clear)
|
Mark M. |
I do not completely understand your permission flow, but you should not be doing anything that needs a runtime permission until you get it, and usually that requires you to do work in onRequestPermissionsResult()
|
Mark M. |
so, you check to see if you hold the permission, and if you do, you go ahead with the protected work... but if you do not hold the permission, you request it, and in onRequestPermissionsResult() you go ahead with the protected work
|
trocchietto_Ivano |
i am logging it on the pc where i have the snippets..
|
trocchietto_Ivano |
one sec
|
Ivano M. | has entered the room |
Ivano M. |
here I am back
|
Jul 31 | 9:50 AM |
Mark M. |
um, hi!
|
Ivano M. |
basically in the call back I have this
|
Ivano M. |
View paste
(2 more lines)
|
Ivano M. |
instead in the onCreate I have all the stuff
|
Ivano M. |
View paste
(31 more lines)
|
Mark M. |
that code will not work if you do not hold the permission
|
Mark M. |
ActivityCompat.requestPermissions() is asynchronous
|
Mark M. |
so, you call that, then blow right on to your CalendarContract code, even though you do not yet hold the permission
|
Mark M. |
the code starting with cr = this.getContentResolver(); through the end should be moved into a separate method
|
Ivano M. |
you mean a kind of asyncTask?
|
Mark M. |
no, just a method
|
Mark M. |
call that method from onCreate() if you already hold the permission, or call it from onRequestPermissionResult() if you are then granted the permission
|
Ivano M. |
but the compiler will not know that
|
Mark M. |
so?
|
Mark M. |
this is covered in many places in my book -- pretty much every example of mine that uses runtime permissions has an AbstractPermissionActivity that wraps up this pattern
|
Ivano M. |
ah you mean an utility class
|
Mark M. |
in my case, it's a method -- the AbstractPermissionActivity handles all the permission work, delegating to the subclass for the actual protected work
|
Jul 31 | 9:55 AM |
Ivano M. | |
Ivano M. |
cool
|
Mark M. |
yes, there are many samples that use that same basic class
|
Ivano M. |
OK I am going to read your chapter on the permissions
|
Ivano M. |
and then look into your AbstractPermissionActivity classes
|
Ivano M. |
and how they get implmented by the one that inherit
|
Mark M. |
when you request permissions in onCreate(), you also run into configuration-change issues, which AbstractPermissionActivity handles
|
Ivano M. |
is also really efficient in terms of clean code
|
Ivano M. |
i mean single responsibility
|
Ivano M. |
by the way if in future I have questions about clean architecture you are skilled on that?
|
Mark M. |
not really
|
Ivano M. |
are you*
|
Ivano M. |
OK
|
Ivano M. |
I love oncle bob
|
Mark M. |
I mean, I know what it is, but I do not claim to be an expert in the subject
|
Ivano M. |
I understand
|
Ivano M. |
thank you for your help you adressed me on the right direction
|
Jul 31 | 10:00 AM |
Mark M. |
OK, that's all for today's chat
|
Mark M. |
the transcript will go up on https://commonsware.com/office-hours/ shortly
|
Mark M. |
the next chat is Thursday at 7:30pm US Eastern
|
Mark M. |
have a pleasant day!
|
trocchietto_Ivano | has left the room |
Ivano M. | has left the room |
Mark M. | turned off guest access |