I know how to delete and insert event in Android.
But the problem is that how can I delete the calendar event inserted by my own app.
Do I need to store all the event_id of the events inserted by my app?
But it seems it is not reliable, right? The event_id may be already become the id of other events. For example, user may manually delete the event that my app inserted and insert their own event which may have the same event_id.
Thank You.
One solution I can think of is using one of the fields to carry some kind of tag unique to your app. Like, in description you could have #MyBooksApp and then search events by that tag.
Of course, user can manually modify the event and it'll not get found but there's no way to work around that, obviously.
Another approach may be to store copy of the event or hash of name and description internally and check whether it's the same event using the hash prior to deleting.
Related
I am new to coding and I am just playing around to build an app where everyone can post new events. So I have already created notes like "user" and "events". The problem I face off is that I dont know how to avoid duplication like for example if two users are posting the excat same event.
I don't want to show them twice in my RecyclerView.
So I have to compare the date, the location and the description, due to this many queries, is the Firebase Realtimedatabase the right "tool"? Or should I use another software.
------/Events
---------/LbwXYVICCl9xd5m..
--------------datum: 10.04.2019
--------------userid: OncDIQis...
--------------location:New York
--------------description:Coldplay
You seem to define two events as being the same based on some of their properties having the same value. In a scenario like that, I'd use those combined properties as the key of the event.
So if you say that two events are the same if they have the same date, location, and description, then you can create the unique key of that event as ${date}_${location}_${description}. For example:
20190410_New York_Coldplay
I've put the date in an easier to search for format, which also filters the .s (since those are not allowed in keys. Now you can store the event under that key:
Events
20190410_New York_Coldplay
datum: 10.04.2019
userid: OncDIQis...
location:New York
description:Coldplay
With the above structure, if another user tries to create an equivalent event, it will get the same key.
Firebase Real-time database is the right tool for you as it updates the database in real time.
At the time of fetching the data from the firebase, you can check whether it is already present in your local database(where you are collecting data fetched from the firebase) or not.
I hope this will help you out.
I have been looking for this quite some time now and i haven't found any answer related to my problem, so before you tag my question duplicate, at least read it first.
First i have just started firebase and only know basic things about it, i am trying to make a simple single user (1 to 1) chat app.
I want to get the number of users logged in in the database.
I have a child to the root of my database called users which have the list of the users who have logged in.
I know about the datashot.getchildrencount() but that works when some update/event happens, but i want it to give me the number of users whenever i want, not only on some event (For example in messenger number of current active users are shown continuously,i dont want active user tho, i just want total logged in users).
I thought of the another way to make a child called NumberofUsers so i store number of users there but then firebase dont allow to getvalue of the child,only set value (it does allow to get value but only on some event). Any idea what should i do?
UPDATE
i thought of another way to do this, though its not working at the moment but i think solving it is easier than thinking of another method to solve my original problem.
so I made one more child of NumberofUsers with key "02" and random value. now everytime i want data of "01" i change the value "02" after enabling the addChildEventListener for "NumberofUsers". Code that does this. Error its giving me. .new database.
Apparently I cant access child data using datasnapshot, any solution?
Any idea how to solve either of this?
Thank you.
Unfortunately, there is no way in which you can read data from a Firebase Database without attaching a listener. Regarding Firebase, everything it's about listeners. In your case, i think you want a callback to be called once and then immediately removed. If so, i recomand you using addListenerForSingleValueEvent() method to simplify this scenario. It triggers once and then does not trigger again.
This is useful for data that only needs to be loaded once and isn't expected to change frequently or require active listening.
Hope it helps.
I know this question a lot here, But I don`t know about this. This is about chat app.
When message get stored into the firebase database. It would become bigger and bigger as time goes by, I want to delete it. and when should I delete this? I just want to left just only last 10 data. It means if I out the app and again go in, It appears only last 10 sentence and I know about the function limitToFirst and limitToLast (but this is not the delete thing.)
If I pay firebase server, you know, if database's data is large It will be more expensive. but I just want to leave just last 10 sentences at least.
when they did come back then they can see the last 10sentence and want to delete except for this. how do I do this?
I saw the answer using the date, but I don`t want that. Is that only answer? If I must do that when I get to delete them? When do I invoke the delete function?
I know how to do that almost, but when? If in the app, there are so many friends and I open the chat screen to chat my friend. That time should I delete them using remove function? How am I saving this for server payment?
I don`t want cost a lot. and I want them to be clear, not dirty in my Firebase database console. so want to delete them. Which is the I have to do? Which time is the best time that I should delete them? When open it ? or when close it ? or when users stop the my app.
You can achieve this in a very simple way. You can use the getChildrenCount() method on the node in which you hold the messages to see the exact number of messages. If you are using as an identifier the random key generated by the push() method, it's very easy to delete the extra messages. Because the records are by default order by date, you can easily query your database using limitToLast(limit) method and than delete the messages like this:
yourRef.child("messages").child(messageId).removeValue();
Another way to achieve this is to use Cloud Functions for Firebase.
Hope it helps.
you can use firebase functions to delete old data when new ones added to the database that is the best time, you can keep the last 100 messages or less.
I'm using the Android Calendar Provider to display events.
I'm also associating the events with images from a local app database by using the EVENT_ID of the event as a reference.
I'm now wondering if it is possible to keep the same reference across multiple devices?
I understand that for the account_type = 'com.google', the GoogleCalendarSyncAdapter uses CalendarContract.EventsColumns.SYNC_DATA1 to store the googleID of the event.
However, it seems that this is not a reliable way to access the data since usage of the SYNC_DATA columns may change at any time and can only be modified by the SyncAdapter.
Is there any other way that I can keep the reference to a calendar provider event across devices?
Embed image IDs into your events
A while ago I had a similar problem with CalendarContract and I solved it by embedding a unique UID tag into the event description text. Clients would parse that tag and retrieve a common UID. That ID is generated on one of the clients using the UUID Java class. However, in my case I was more interested in identifying events created with my app.
In your case I assume that your image database references are stable IDs that are consistent across all app installations. You could insert a tag into the event description text that references the image from your DB such as:
<myapp:imgid_1234>
Alternatively you could also add a special "resource type" attendee to your event that adds that image reference to an event: imgid_1234#yourappname.com. This option would keep the event description clean and may lower accidental deletion through the user.
I'd like to add a new calendar for my application (to divide it from other events), as GMail does.
If there isn't a way to that, how could we delete our events from the calendar when the app is disinstalled?
Thanks in advance.
The contract for the calendars can be found here. However, you need the account name and type to be able to insert a new calendar. I'm guessing gmail can do this since it has your google account info - I'm not sure if your app will be able to do the same.
As for your second questions, here is the spec for calendar events. You will just need to know the _ID of the event in the DB to be able to remove it (which you should be able to get fairly easily).
Events can be deleted either by the _ID as an appended id on the Uri or using any standard selection. If an appended id is used a selection is not allowed. There are two versions of delete: as an app and as a sync adapter. An app delete will set the deleted column on an event and remove all instances of that event. A sync adapter delete will remove the event from the database and all associated data.