Sketchware में एक Simple Reminder App कैसे बनाएं (AlarmManager के साथ)
इस पोस्ट में हम एक simple reminder app बनाएंगे जो Sketchware में AlarmManager का इस्तेमाल करता है। नीचे पूरे steps दिए गए हैं:
---
1. सबसे पहले Sketchware में एक नया प्रोजेक्ट बनाओ।
---
2. main.xml में ये चीज़ें ऐड करो:
एक EditText डालो – edittext1
एक Button डालो – button1 (reminder टाइम सेट करने के लिए)
एक TextView – textview1 (तारीख और टाइम दिखाने के लिए)
एक और Button – button2 (reminder सेट करने के लिए)
एक ListView – listview1 (reminders लिस्ट दिखाने के लिए)
---
3. Image Manager में दो इमेज ऐड करो:
ic_notifications_black
ic_delete_black
---
4. एक custom view बनाओ – items.xml
इसमें दो TextView डालो – textview1 और textview2
और एक ImageView – imageview1.
---
5. ListView listview1 को custom view से जोड़ दो (items.xml select करो custom view में)
---
6. AppCompat और Design दोनों को On कर दो।
---
7. ये components ऐड करो:
दो Calendar component: cal और cal2
एक SharedPreferences: sp नाम से
एक Dialog component: dialog
---
8. Variables बनाओ:
तीन number variables: reminder_code, current_time, code
एक String variable: message
एक Map variable: map
एक ListMap: maplist
---
9. एक more block बनाओ – createNotificationChannel
और इसमें ये Java code ऐड करो:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(
"reminder_channel",
"Reminders",
NotificationManager.IMPORTANCE_HIGH
);
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(channel);
}
--- 10. initializeLogic में createNotificationChannel वाला more block कॉल करो।
DatePickerDialog datePicker = new DatePickerDialog(
this,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month);
cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
_pickTime();
}
},
cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH),
cal.get(Calendar.DAY_OF_MONTH)
);
datePicker.show();
---
14. pickTime more block में ये Java code डालो:
TimePickerDialog timePicker = new TimePickerDialog(
this,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
cal.set(Calendar.HOUR_OF_DAY, hourOfDay);
cal.set(Calendar.MINUTE, minute);
cal.set(Calendar.SECOND, 0);
textview1.setText(new SimpleDateFormat("dd/MM/yyyy hh:mm a").format(cal.getTime()));
}
},
cal.get(Calendar.HOUR_OF_DAY),
cal.get(Calendar.MINUTE),
true
);
timePicker.show();
---
15. button1 के onClick में pickDate वाला block यूज़ करो।
---
16. Java Manager में ReminderReceiver.java नाम से नई फाइल बनाओ और इसमें ये कोड डालो:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
public class ReminderReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String title = intent.getStringExtra("title");
String message = intent.getStringExtra("message");
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "reminder_channel")
.setSmallIcon(R.drawable.ic_notifications_black)
.setContentTitle(title)
.setContentText(message)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setAutoCancel(true);
NotificationManagerCompat manager = NotificationManagerCompat.from(context);
manager.notify(1, builder.build());
}
}
17. Manifest में App Components में ये लाइन डालो:
<receiver android:name=".ReminderReceiver" />
---
18. एक और more block बनाओ – schedule_reminder [String: message] at [Calendar:calendar] with (number:code)
और इसमें ये Java कोड डालो:
Intent intent = new Intent(this, ReminderReceiver.class);
intent.putExtra("title", "Reminder");
intent.putExtra("message", _message);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
this, (int)_code, intent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.setExactAndAllowWhileIdle(
AlarmManager.RTC_WAKEUP,
_calendar.getTimeInMillis(),
pendingIntent
);
---
19. एक और more block बनाओ – cancel_reminder [String: message] at [Calendar:calendar] with (number:code)
इसमें ये Java कोड डालो:
Intent intent = new Intent(this, ReminderReceiver.class);
intent.putExtra("title", "Reminder");
intent.putExtra("message", _message);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
this, (int)_code, intent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
---
20. button2 के onClick में reminder सेट करने का code लगाओ:





