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