我已经可以在通知栏中显示一个图标,如下面的代码所示。当用户单击此图标时,我想启动一个新活动 ( myclass
),但我不知道如何执行此操作。我应该把意图放在哪里?
public class NotificationActivity extends Activity {
AlarmManager am;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notification);
am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
setRepeatingAlarm();
}
public void setRepeatingAlarm() {
Intent intent = new Intent(this, TimeAlarm.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,
intent, PendingIntent.FLAG_CANCEL_CURRENT);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
(20 * 1000), pendingIntent);
System.out.println("Calling Alaram...");
}
}
public class BootUpReciever extends BroadcastReceiver {
NotificationManager nm;
@Override
public void onReceive(Context context, Intent intent) {
System.out.println("in broad....");
nm = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence from = "Lokesh";
CharSequence message = "Notification Test...";
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(), 0);
Notification notif = new Notification(R.drawable.cherry_icon,
"Notification Test...", System.currentTimeMillis());
notif.setLatestEventInfo(context, from, message, contentIntent);
nm.notify(1, notif);
if ((intent.getAction() != null) &&
(intent.getAction().equals("android.intent.action.BOOT_COMPLETED")))
{
System.out.println("in broadcast receiver.....");
Intent i = new Intent(context, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}