Back to project page notify-me-android.
The source code is released under:
MIT License
If you think the Android project notify-me-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.contexthub.notifyme.push; // w w w. j av a2 s .c om import android.app.Notification; import android.app.NotificationManager; import android.content.Context; import android.graphics.BitmapFactory; import android.os.Bundle; import android.support.v4.app.NotificationCompat; import android.text.TextUtils; import android.util.Log; import com.chaione.contexthub.sdk.ContextHub; import com.chaione.contexthub.sdk.push.PushPayloadHandler; import com.contexthub.notifyme.Constants; import com.contexthub.notifyme.R; import com.contexthub.notifyme.model.PushNotificationHistory; /** * Handles the receipt of ContextHub push notifications */ public class NotificationHandler implements PushPayloadHandler { private static final int NOTIFICATION_ID = 1; @Override public void handlePushPayload(Context context, Bundle bundle) { PushNotificationHistory.save(bundle); // Use ContextHub's instance of the Otto event bus to trigger history refresh in PushReceiveFragment ContextHub.getInstance().getBus().post(new PushReceivedEvent()); String message = bundle.getString(Constants.KEY_MESSAGE, ""); if(!TextUtils.isEmpty(message)) { showNotification(context, bundle); } else { Log.d(getClass().getName(), bundle.toString()); } } private void showNotification(Context context, Bundle bundle) { String message = bundle.get(Constants.KEY_MESSAGE).toString(); NotificationManager manager = NotificationManager.class.cast(context.getSystemService(Context.NOTIFICATION_SERVICE)); Notification notification = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher)) .setContentTitle(context.getString(R.string.app_name)) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)) .setContentText(message) .setAutoCancel(false) .setVibrate(new long[]{100, 500, 100, 500}) .build(); manager.notify(NOTIFICATION_ID, notification); } public class PushReceivedEvent{} }