您好我正在尝试根据 SQL 数据库的输入设置通知。当我尝试保存输入的数据时,我收到错误 AlarmReciever Activity Not Found;
我最初在清单中有这个
<receiver android:process=":remote" android:name="AlarmReciever"></receiver>
当我在清单中添加以下内容时,我得到一个类似的错误,无法找到显式类。任何建议将不胜感激。
<activity
android:name=".AlamReciever"
android:label="@string/title_activity_user_menu" >
</activity>
Addcourse 课程片段
public void onClick (View addModuleButton)
{
String moduleCode = sqlModuleCode.getText().toString();
String moduleName = sqlModuleName.getText().toString();
String moduleType = spinnerModuleType.getSelectedItem().toString();
String moduleDay = spinnerModuleDay.getSelectedItem().toString();
String moduleStartHour = timePickerStart.getCurrentHour().toString();
String moduleStartMinute = timePickerStart.getCurrentMinute().toString();
String moduleEndHour = timePickerEnd.getCurrentHour().toString();
String moduleEndMinute = timePickerEnd.getCurrentMinute().toString();
String moduleLocation = sqlModuleLocation.getText().toString();
String moduleComments = sqlModuleComments.getText().toString();
MODULEDATABASE = new database(AddCourse.this);
MODULEDATABASE.openToWrite();
MODULEDATABASE.createEntry(moduleCode , moduleName, moduleType, moduleDay, moduleStartHour,
moduleStartMinute, moduleEndHour, moduleEndMinute, moduleLocation, moduleComments);
int Hour = Integer.parseInt(moduleStartHour);
int Minute = Integer.parseInt(moduleStartMinute);
Calendar cal = Calendar.getInstance();
int currentDay = cal.get(Calendar.DAY_OF_WEEK);
int setDay = 0;
if(moduleDay=="Sunday")
{
setDay = 1;
}
else if(moduleDay=="Monday")
{
setDay = 2;
}
else if(moduleDay=="Tuesday")
{
setDay = 3;
}
else if(moduleDay=="Wednesday")
{
setDay = 4;
}
else if(moduleDay=="Thursday")
{
setDay = 5;
}
else if(moduleDay=="Friday")
{
setDay = 6;
}
else if(moduleDay=="Saturday")
{
setDay = 7;
}
cal.set(Calendar.DAY_OF_WEEK,4);
cal.set(Calendar.HOUR_OF_DAY,Hour);
cal.set(Calendar.MINUTE, Minute);
Intent intent = new Intent(AddCourse.this, AlarmReciever.class);
intent.putExtra("alarm_message",moduleName+ "is about to begin");
PendingIntent sender = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// Get the AlarmManager service
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
long weekly = AlarmManager.INTERVAL_DAY * 7;
am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),weekly,sender);
startActivity(intent);
报警接收器类
public class AlarmReciever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NotificationCompat.Builder nb = new NotificationCompat.Builder(context);
nb.setContentTitle("title");
nb.setContentText("message");
nb.setSmallIcon(R.drawable.ic_launcher);
NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
final Intent notificationIntent = new Intent(context, AddCourse.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
final PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
nb.setContentIntent(contentIntent);
Notification notification = nb.getNotification();
nm.notify(0, notification);
}
}
目录日志
11-07 12:51:41.195: E/AndroidRuntime(3927): Uncaught handler: thread main exiting due to uncaught exception
11-07 12:51:41.216: E/AndroidRuntime(3927): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.mycoursetimetable/com.example.mycoursetimetable.AlarmReciever}; have you declared this activity in your AndroidManifest.xml?
11-07 12:51:41.216: E/AndroidRuntime(3927): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
11-07 12:51:41.216: E/AndroidRuntime(3927): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
11-07 12:51:41.216: E/AndroidRuntime(3927): at android.app.Activity.startActivityForResult(Activity.java:2749)
11-07 12:51:41.216: E/AndroidRuntime(3927): at android.app.Activity.startActivity(Activity.java:2855)
11-07 12:51:41.216: E/AndroidRuntime(3927): at com.example.mycoursetimetable.AddCourse.onClick(AddCourse.java:169)
11-07 12:51:41.216: E/AndroidRuntime(3927): at android.view.View.performClick(View.java:2364)
11-07 12:51:41.216: E/AndroidRuntime(3927): at android.view.View.onTouchEvent(View.java:4179)
11-07 12:51:41.216: E/AndroidRuntime(3927): at android.widget.TextView.onTouchEvent(TextView.java:6541)
11-07 12:51:41.216: E/AndroidRuntime(3927): at android.view.View.dispatchTouchEvent(View.java:3709)
11-07 12:51:41.216: E/AndroidRuntime(3927): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-07 12:51:41.216: E/AndroidRuntime(3927): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-07 12:51:41.216: E/AndroidRuntime(3927): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-07 12:51:41.216: E/AndroidRuntime(3927): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-07 12:51:41.216: E/AndroidRuntime(3927): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-07 12:51:41.216: E/AndroidRuntime(3927): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
11-07 12:51:41.216: E/AndroidRuntime(3927): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
11-07 12:51:41.216: E/AndroidRuntime(3927): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
11-07 12:51:41.216: E/AndroidRuntime(3927): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
11-07 12:51:41.216: E/AndroidRuntime(3927): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
11-07 12:51:41.216: E/AndroidRuntime(3927): at android.os.Handler.dispatchMessage(Handler.java:99)
11-07 12:51:41.216: E/AndroidRuntime(3927): at android.os.Looper.loop(Looper.java:123)
11-07 12:51:41.216: E/AndroidRuntime(3927): at android.app.ActivityThread.main(ActivityThread.java:4363)
11-07 12:51:41.216: E/AndroidRuntime(3927): at java.lang.reflect.Method.invokeNative(Native Method)
11-07 12:51:41.216: E/AndroidRuntime(3927): at java.lang.reflect.Method.invoke(Method.java:521)
11-07 12:51:41.216: E/AndroidRuntime(3927): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
11-07 12:51:41.216: E/AndroidRuntime(3927): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
11-07 12:51:41.216: E/AndroidRuntime(3927): at dalvik.system.NativeStart.main(Native Method)