Skip to content

Instantly share code, notes, and snippets.

@Aiur3908
Created April 30, 2015 07:54
Show Gist options
  • Save Aiur3908/c5f6a7eaa8bc48bae97d to your computer and use it in GitHub Desktop.
Save Aiur3908/c5f6a7eaa8bc48bae97d to your computer and use it in GitHub Desktop.
private void sendNotification() {
int notificationId = 001;
//決定這個notification的辨識編號
NotificationCompat.BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
bigStyle.bigText("很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長的文章");
//建立一個BigTextStyle的物件,並且設定其文章的內容。
NotificationCompat.Builder notifcaition =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Title")
.setContentText("很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長的文章")
.setStyle(bigStyle);
//雖然上面有設定文章內容了,但是創建Notification物件時,還是必須setContentText!
//最後在setStyle,將剛才的BigTextStyle物件丟入即可
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
//取得NotificationManagerCompat的實體
notificationManagerCompat.notify(notificationId , notifcaition.build());
//填入辨識編號及notification後,即可發送出去
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment