I have inserted an event in a calendar. The time of event created must also be created with alarm of the same time to ring. How to do it? I have used following code and it gives folowing error.
I get 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);
OnReceive method overrided:
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 got:
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.todoapplication/android.todoapplication.AlarmReceiver}; have you declared this activity in your AndroidManifest.xml?
Any Help is highly appreciated and thanks in advance...
Try to add your activity "AlarmReceiver" in your AndroidManifest.xml
.
If your activity extends an Android Receiver (E.g: BroadcastReceiver), Add it like this :
<application android:label="@string/app_name" ...>
...
<receiver android:name=".AlarmReceiver" android:process=":remote" />
</application>
else
<application android:label="@string/app_name" ...>
...
<activity android:name=".AlarmReceiver"/>
</application>
精彩评论