Skip to content

Instantly share code, notes, and snippets.

@Tikitoo
Created February 12, 2015 06:22
Show Gist options
  • Save Tikitoo/28558a0ad43a3826c88a to your computer and use it in GitHub Desktop.
Save Tikitoo/28558a0ad43a3826c88a to your computer and use it in GitHub Desktop.
Create a Notification demo
public void onCreate() {
super.onCreate();
Log.d(TAG, "onCreate Method");
// 创建Notification 对象
Notification notif = new Notification(R.drawable.abc_ic_menu_cut_mtrl_alpha,
"This is Notification", System.currentTimeMillis());
// 点击Notification 进入MainActivity
Intent notifIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
notifIntent, 0);
// 设置Notification 详细信息
notif.setLatestEventInfo(this, "title", "This is Notification content",
pendingIntent);
startForeground(1, notif);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment