I inserted the event into the calendar. Event creation time must also be generated with an alarm. How to do it? I used the following code and it gives the following error.
I get the following error when I use the following code: Main activity:
Calendar caln = Calendar.getInstance(); caln.add(Calendar.SECOND, 2); Intent intent = new Intent(ToDoApplicationActivity.this, AlarmReceiver.class); intent.putExtra("alarm_message", title1); PendingIntent sender = PendingIntent.getBroadcast(this, 192837, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender); startActivity(intent);
The OnReceive method is overridden:
public void onReceive(Context context, Intent intent) { try { Bundle bundle = intent.getExtras(); String message = bundle.getString("alarm_message"); Intent newIntent = new Intent(context, ToDoApplicationActivity.class); newIntent.putExtra("alarm_message", message); newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(newIntent); } catch (Exception e) { Toast.makeText(context, "There was an error somewhere, but we still received an alarm", Toast.LENGTH_SHORT).show(); e.printStackTrace(); } }
ERROR:
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.todoapplication / android.todoapplication.AlarmReceiver}; Have you announced this activity in your AndroidManifest.xml?
Any help is greatly appreciated and thanks in advance ...
source share