Create your Firebase Realtime database Calendar App to store events or reminders - Android 13 API 33
HTML-код
- Опубликовано: 23 ноя 2024
- In this video it shows the steps to create your firebase database based Calendar App. This App can be used to store your reminders or events in your firebase database.
I hope you like this video. For any questions, suggestions or appreciation please contact us at: programmerworl... or email at: programmerworld1990@gmail.com
Complete source code and other details/ steps of this video are posted in the below link:
programmerworl...
However, the main Java code is copied below also for reference:
package com.programmerworld.firebasecalendarapp;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CalendarView;
import android.widget.EditText;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
public class MainActivity extends AppCompatActivity {
private CalendarView calendarView;
private EditText editText;
private String stringDateSelected;
private DatabaseReference databaseReference;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
calendarView = findViewById(R.id.calendarView);
editText = findViewById(R.id.editText);
calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(@NonNull CalendarView calendarView, int i, int i1, int i2) {
stringDateSelected = Integer.toString(i) + Integer.toString(i1+1) + Integer.toString(i2);
calendarClicked();
}
});
databaseReference = FirebaseDatabase.getInstance().getReference("Calendar");
}
private void calendarClicked(){
databaseReference.child(stringDateSelected).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (snapshot.getValue() != null){
editText.setText(snapshot.getValue().toString());
}else {
editText.setText("null");
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
}
public void buttonSaveEvent(View view){
databaseReference.child(stringDateSelected).setValue(editText.getText().toString());
}
}
-
thank you for this great video. It helped me a lot!
have a nice day :)
Thank you for sharing this
How could I make it for multiple users, for example one user creates a calendar and another user could join it, and both can edit and view changes?
Hi! Thank you very much for this nice video. This really helps a lot. I just wonder is this also possible to put the annual alarm to this app and how to do it. Thanks!
Can you write the code for storing the multiple events on particular dat
How you make the date change color after you save the data?
Any videos about View Model?
Could you please give more details about View Model or details on your requirement?
programmerworld.co
Best video! can it be used in kotlin language?
Yes, any Android app code written in Java can also be implemented using Kotlin language (which is in fact preferred language for App development by Android).
Now, you can either re-write the code in Kotlin with overall concept remains same as shown in this video.
Or you can simply use the tool as shown in the below to convert the Java code into Kotlin code:
programmerworld.co/android/how-to-convert-the-java-code-to-kotlin-for-your-app-in-android-studio/
Hope above helps.
Cheers
Programmer World
programmerworld.co
-
Hi, what should i do if i want to add a event every 4 hour in a day. Thank you
In this example I have only considered the date field for setting the events. However, one can enhance it by adding time field as well. The only change required will be that in the Firebase database a time field node will be required to be added (under each date field).
For reference, complete source code and details shown in this video is also shared in the below link:
programmerworld.co/android/create-your-firebase-realtime-database-calendar-app-to-store-events-or-reminders-android-13-api-33/
Sir
If I'm click save done button
Data not save in firebase
Screen automatically closed
Basically the App is crashing on clicking the Save button.
In the Save button, below line of code is executed:
databaseReference.child(stringDateSelected).setValue(editText.getText().toString());
So, my guess is most likely the databaseReference object is null and hence exception is thrown and App closes.
To handle the exception, surround the above line of code within Try-catch block as shown below:
try{
databaseReference.child(stringDateSelected).setValue(editText.getText().toString());
}
catch(Exception e){
}
And then read the value of exception "e" (either in debug mode or print this value in log file).
Now, to resolve this issue, check whether this object is properly created or not in the onCreate method of your code. Below line should be checked.
databaseReference = FirebaseDatabase.getInstance().getReference("Calendar");
Some of the probable reasons could be that the connection to db is not proper due to network issues or json file not properly placed in the project folder.
For reference, details shown in this video is also shared in the below link:
programmerworld.co/android/create-your-firebase-realtime-database-calendar-app-to-store-events-or-reminders-android-13-api-33/
Cheers
Programmer World
programmerworld.co
-
@@ProgrammerWorld It works in mine, thank you bro.
Database showed many error
Could you copy the errors you are observing?
For reference, details shown in this video is also shared in the below link:
programmerworld.co/android/create-your-firebase-realtime-database-calendar-app-to-store-events-or-reminders-android-13-api-33/
Cheers
Programmer World
programmerworld.co
-
And how to make it so that every day at a certain time from 9 to 12, for example, one code works and at other times another code works or screenshots or activiti are launched
I think you are looking for alarm kind of service which runs in background process. Any of the below may help in this regards. Please refer:
programmerworld.co/android/how-to-create-background-process-in-your-android-app/
programmerworld.co/android/how-to-create-service-class-to-run-a-custom-alarm-clock-in-your-android-complete-source-code/
programmerworld.co/android/create-a-simple-alarm-clock-app-in-android-studio/
Cheers
Programmer World
programmerworld.co
-
DOES NOT WORK!
What is the error or exception it is throwing? If you could more details of the issue then it may help us in checking it out.
By the way the complete source code is available in the below link as well. You may refer it:
programmerworld.co/android/create-your-firebase-realtime-database-calendar-app-to-store-events-or-reminders-android-13-api-33/
Cheers
Programmer World
programmerworld.co
-