Last active
January 20, 2016 06:04
-
-
Save a1yama/489c426978a89c6a74ea 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
Bundle bundle = intent.getExtras(); | |
String message = bundle.getString("message"); | |
try { | |
Bundle extras = intent.getExtras(); | |
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); | |
String messageType = gcm.getMessageType(intent); | |
if (!extras.isEmpty()) { | |
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()); | |
builder.setSmallIcon(R.drawable.ic_launcher); | |
builder.setContentTitle("ContentText"); // 1行目 | |
builder.setContentText(message); // 2行目 | |
builder.setWhen(System.currentTimeMillis()); // タイムスタンプ(現在時刻、メール受信時刻、カウントダウンなどに使用) | |
builder.setTicker("Ticker"); // 通知到着時に通知バーに表示(4.4まで) | |
// 5.0からは表示されない | |
NotificationManagerCompat manager = NotificationManagerCompat.from(getApplicationContext()); | |
// タップするとキャンセル(消える) | |
builder.setAutoCancel(true); | |
manager.notify(bundle.getInt("UID"), builder.build()); | |
} | |
} finally { | |
// 必ず実行する | |
GcmBroadcastReceiver.completeWakefulIntent(intent); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment