How to create an alarm when creating a calendar event?

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 ...

+4
source share
1 answer

Try adding your "AlarmReceiver" activity to AndroidManifest.xml .
If your activity extends your Android receiver (e.g. BroadcastReceiver), add it like this:

 <application android:label="@string/app_name" ...> ... <receiver android:name=".AlarmReceiver" android:process=":remote" /> </application> 

yet

 <application android:label="@string/app_name" ...> ... <activity android:name=".AlarmReceiver"/> </application> 
+2
source

All Articles