Skip to content

Instantly share code, notes, and snippets.

@a1yama
Last active January 20, 2016 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a1yama/489c426978a89c6a74ea to your computer and use it in GitHub Desktop.
Save a1yama/489c426978a89c6a74ea to your computer and use it in GitHub Desktop.
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