在我的程序中,单击通知,它必须转到当前运行的活动。我找到了许多方法,但都失败了。请帮助我。 这是我的闹钟管理员......
private void startAlarm(long time,String stringtime){
AlarmManager alarmManager = (AlarmManager) this.getSystemService(this.ALARM_SERVICE);
final int _id=(int) System.currentTimeMillis();
Intent myIntent=new Intent(getApplicationContext(),timealarm.class);
myIntent.putExtra("Start_time", stringtime);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(),_id, myIntent, 0);
alarmManager.set(AlarmManager.RTC, time, pendingIntent);
//sendBroadcast(myIntent);
}
这是广播.....
public void onReceive(Context context, Intent paramIntent) {
// TODO Auto-generated method stub
paramIntent.getStringExtra("Start_time");
Intent myIntent=new Intent(context,service.class);
myIntent.putExtra("Strar_time",paramIntent.getStringExtra("Start_time") );
myIntent.setAction(Intent.ACTION_MAIN);
myIntent.addCategory(Intent.CATEGORY_LAUNCHER);
context.startService(myIntent);
}
这是服务.....
public void onStart(Intent intent, int startId)
{
super.onStart(intent, startId);
String startTime = intent.getStringExtra("Strar_time");
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
long when = System.currentTimeMillis(); // notification time
int ww = (int) System.currentTimeMillis();
Notification notification = new Notification(R.drawable.ic_launcher, "reminder", when);
notification.defaults |= Notification.DEFAULT_SOUND;
notification.flags |= notification.FLAG_AUTO_CANCEL;
notification.vibrate = new long[]{100, 200, 100, 500};
notification.defaults = Notification.DEFAULT_ALL;
Intent notificationIntent = new Intent(this, Goo.class);
PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), ww, notificationIntent , PendingIntent.FLAG_ONE_SHOT);
notification.setLatestEventInfo(getApplicationContext(), "It's about time", "Your time is "+startTime, contentIntent);
nm.notify(NOTIF_ID, notification);
NOTIF_ID++;
Log.i("NotiID",NOTIF_ID+"");
if(NOTIF_ID == 2147483647){
NOTIF_ID = 1;
Log.i("pyyfwjflwej",NOTIF_ID+"");
}
stopSelf();
}