private static int App_Notification_ID_BASE = 911;
private static PendingIntent appDIndent;
private static NotificationManager appMange;
private static Notification appNF;
/**
* 在Activity
onCreate
中调用此方法
* @param paramContext
* @param paramClass
*/
public void startAppNotification(Context paramContext, Class<?> paramClass)
{
if (appMange == null)
{
appMange = (NotificationManager)getSystemService("notification");
Intent localIntent = new Intent(this, paramClass);
localIntent.setAction("android.intent.action.MAIN");
localIntent.addCategory("android.intent.category.LAUNCHER");
localIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
appDIndent = PendingIntent.getActivity(paramContext, 0, localIntent, 134217728);
appNF = new Notification();
appNF.icon = 2130837545;
appNF.tickerText = getResources().getString(2131099648);
appNF.defaults = (0x1 | appNF.defaults); //声音提醒
appNF.flags =
FLAG_ONGOING_EVENT ; //设置清除不掉
RemoteViews localRemoteViews = new RemoteViews(getPackageName(), 2130903046);
appNF.contentView = localRemoteViews;
appNF.contentIntent = appDIndent;
appMange.notify(App_Notification_ID_BASE, appNF);
}
}
startAppNotification(getApplicationContext(), WelcomeActivity.class);
注意WelcomeActivity的android:launchMode要是标准模式