我正在研究andorid中的Notification。
此处代码是通知到达....
@Override
public void onReceive(Context context, Intent intent) {
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
mBuilder.setSmallIcon(R.drawable.ic_launcher);
mBuilder.setTicker("New Task Here!!!");
if(taskdata.get(0).getDescription().equals(""))
{
int stringId = context.getApplicationInfo().labelRes;
String appname = context.getString(stringId);
mBuilder.setContentTitle(appname);
}
else
{
mBuilder.setContentTitle(taskdata.get(0).getDescription());
}
long l = Long.parseLong(taskdata.get(0).getDateTime());
Date date =new Date(l);
SimpleDateFormat formatter = new SimpleDateFormat("hh:mm a ");
String alarmtime = formatter.format(date);
String dateString= DateFormat.format("dd/MM/yyyy",date).toString();
mBuilder.setContentText(alarmtime+","+dateString);
Intent resultIntent = new Intent(context, TaskDetail.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
Bundle bundledata = new Bundle();
bundledata.putString("ImagePath", taskdata.get(0).getImagePath());
bundledata.putString("Des", taskdata.get(0).getDescription());
bundledata.putString("DateTime", FlagValue);
resultIntent.putExtras(bundledata);
stackBuilder.addParentStack(TaskDetail.class);
//ringtone on
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(context, notification);
r.play();
/* Increase notification number every time a new notification arrives */
mBuilder.setNumber(++numMessages);
mBuilder.setAutoCancel(true);
// Adds the Intent that starts the Ac tivity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
// here this activity will refresh when fire the receive
Intent activityintent = new Intent(context,MainActivity.class);
PendingIntent contentintent = PendingIntent.getActivity(context, 0, activityintent, PendingIntent.FLAG_UPDATE_CURRENT);
activityintent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
activityintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(resultPendingIntent);
mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// notificationID allows you to update the notification later on.
mNotificationManager.notify(notificationID, mBuilder.build());
}
我的问题是:
MyActivity.class
活动将刷新。我也推荐此链接Android Refresh Activity from Notification,但在我的应用程序中并非如此。
如果您有任何想法请帮助我。
先谢谢你。
答案 0 :(得分:0)
在通知功能的末尾添加以下功能。
onCreate(null)