0
我现在有,当按下的按钮的应用程序,并在一定的时间周期之后,一个状态通知设置。如果用户没有在应用程序中打开,通知出现时,应用程序也重新打开AlarmManager起始应用,而不是仅仅发送通知
一切工作从事实上除了罚款。这不是我想要发生的事情。我希望通知自己出现(无论用户在哪里)。
在我按下按钮,我使用:
// get a Calendar object with current time
Calendar cal = Calendar.getInstance();
// add minutes to the calendar object
cal.add(Calendar.SECOND, time);
Intent alarmintent = new Intent(getApplicationContext(), AlarmReceiver.class);
alarmintent.putExtras(bundle);
// In reality, you would want to have a static variable for the request code instead of 192837
PendingIntent sender = PendingIntent.getBroadcast(getApplicationContext(), HELLO_ID, alarmintent, 0);
// Get the AlarmManager service
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
这就要求我AlarmReceiver.class,使用这个代码来调用我的通知类:
Intent myIntent = new Intent(context, Note.class);
myIntent.putExtras(bundle2);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(myIntent);
notification.class :
public class Note extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String ns = Context.NOTIFICATION_SERVICE;
final NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.launcher;
CharSequence tickerText = "Remind Me!";
long when = System.currentTimeMillis();
final Notification notification = new Notification(icon, tickerText, when);
notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_NO_CLEAR;
final Context context = getApplicationContext();
CharSequence contentTitle = "Remind Me!";
CharSequence contentText = param1;
Intent notificationIntent = new Intent(context, Completed.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(HELLO_ID, notification);
HELLO_ID++;
}
}
启动的音符活动,因为它是所有设置通知,右边是罚款?问题在于,如果应用程序关闭,它会再次显示主要活动。 – 2011-01-19 18:55:33