Skip to content

Instantly share code, notes, and snippets.

private void sendNotification()
{
int notificationId = 001;
//決定這個notification的辨識編號
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Title")
.setContentText("內容");
private void sendNotification()
{
int notificationId = 001;
//決定這個notification的辨識編號
Intent intent = new Intent(this , MainActivity.class);
//建立Intent , 並決定要開啟哪個class
PendingIntent pendingIntent =
PendingIntent.getActivity(this, 0, intent, 0);
//使用PendingIntent來等待執行這個intent
private void sendNotification()
{
int notificationId = 001;
//決定這個notification的辨識編號
Intent intent = new Intent(this , MainActivity.class);
//建立Intent , 並決定要開啟哪個class
PendingIntent pendingIntent =
PendingIntent.getActivity(this, 0, intent, 0);
//使用PendingIntent來等待執行這個intent
private void sendNotification()
{
int notificationId = 001;
//決定這個notification的辨識編號
Intent mapIntent = new Intent(Intent.ACTION_VIEW);
//建立Intent , 這次改ACTION_VIEW
Uri geoUri = Uri.parse("geo:0,0?q=" + Uri.encode("台北火車站"));
//建立一個Uri,假設要找台北火車站。
mapIntent.setData(geoUri);
private void sendNotification()
{
int notificationId = 001;
//決定這個notification的辨識編號
Intent mapIntent = new Intent(Intent.ACTION_VIEW);
//建立Intent , 這次改ACTION_VIEW
Uri geoUri = Uri.parse("geo:0,0?q=" + Uri.encode("台北火車站"));
//建立一個Uri,假設要找台北火車站。
mapIntent.setData(geoUri);
private void sendNotification() {
int notificationId = 001;
//決定這個notification的辨識編號
NotificationCompat.BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
bigStyle.bigText("很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長很長的文章");
//建立一個BigTextStyle的物件,並且設定其文章的內容。
NotificationCompat.Builder notifcaition =
private void sendNotification() {
int notificationId = 001;
//決定這個notification的辨識編號
Bitmap bitmap = BitmapFactory.decodeResource(getResources() , R.drawable.a1);
//取得要發送的圖片
NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
bigPictureStyle.bigPicture(bitmap);
//創建一個BigPictureStyle物件,並設定要傳送的圖片
private void sendNotification() {
int notificationId = 001;
//決定這個notification的辨識編號
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
inboxStyle.setBigContentTitle("InboxStyle")
.addLine("第一行")
.addLine("第二行")
.addLine("第三行")
.addLine("第四行")
NotificationCompat.Builder notifcaition =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("標題")
.setGroup("News")
.setContentText("內容");
//setGroup 設定同一個Key即可
private void sendNotification() {
int notificationId = 001;
//決定這個notification的辨識編號
NotificationCompat.Builder notifcaition =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("標題")
.setContentText("內容");
//創建一個主要的Notification物件