Skip to content

Instantly share code, notes, and snippets.

@nightbear1009
Created May 27, 2015 14:39
Show Gist options
  • Save nightbear1009/dd8d5a02f9dd566888c0 to your computer and use it in GitHub Desktop.
Save nightbear1009/dd8d5a02f9dd566888c0 to your computer and use it in GitHub Desktop.
heads-up notification
Intent notificationIntent = new Intent(MainActivity.this,MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);
Notification notification = new Notification.Builder(MainActivity.this)
.setSmallIcon(R.drawable.ic_launcher)
.setFullScreenIntent(contentIntent, true)
.addAction(R.drawable.ic_launcher,"add",contentIntent)
.build();
final int notifyID = 1; // 通知的識別號碼
final NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // 取得系統的通知服務
notificationManager.notify(notifyID, notification);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment