Android Open Source - awareness-android Notification Handler






From Project

Back to project page awareness-android.

License

The source code is released under:

MIT License

If you think the Android project awareness-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.

Java Source Code

package com.contexthub.awareness.push;
/*from w w  w  .  ja va2s  . c o m*/
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 com.chaione.contexthub.sdk.push.PushPayloadHandler;
import com.contexthub.awareness.R;

/**
 * Created by andy on 11/10/14.
 */
public class NotificationHandler implements PushPayloadHandler {

    private static final int NOTIFICATION_ID = 1;
    private static final String KEY_MESSAGE = "message";

    @Override
    public void handlePushPayload(Context context, Bundle bundle) {
        if(bundle.containsKey(KEY_MESSAGE)) {
            showNotification(context, bundle);
        }

    }

    private void showNotification(Context context, Bundle bundle) {
        String message = bundle.get(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);
    }
}




Java Source Code List

com.contexthub.awareness.ApplicationTest.java
com.contexthub.awareness.AwarenessApp.java
com.contexthub.awareness.push.NotificationHandler.java
com.contexthub.awareness.ui.BeaconsActivity.java
com.contexthub.awareness.ui.ChildListActivity.java
com.contexthub.awareness.ui.GeofencesActivity.java
com.contexthub.awareness.ui.MainActivity.java
com.contexthub.awareness.ui.PushActivity.java
com.contexthub.awareness.ui.VaultActivity.java
com.contexthub.awareness.ui.fragments.AboutFragment.java
com.contexthub.awareness.ui.fragments.ContextualObjectsFragment.java
com.contexthub.awareness.ui.widget.DividerItemDecoration.java
com.contexthub.awareness.ui.widget.Item.java
com.contexthub.awareness.ui.widget.ItemsAdapter.java
com.contexthub.awareness.ui.widget.SimpleSectionedRecyclerViewAdapter.java
com.contexthub.awareness.ui.widget.ViewHolder.java