Created
April 30, 2015 07:54
-
-
Save Aiur3908/c5f6a7eaa8bc48bae97d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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