Example usage for android.app Notification CATEGORY_PROMO

List of usage examples for android.app Notification CATEGORY_PROMO

Introduction

In this page you can find the example usage for android.app Notification CATEGORY_PROMO.

Prototype

String CATEGORY_PROMO

To view the source code for android.app Notification CATEGORY_PROMO.

Click Source Link

Document

Notification category: promotion or advertisement.

Usage

From source file:graaby.app.wallet.services.GcmIntentService.java

private void sendNotification(final String msg) {
    try {//from  w w w  . java2  s . c om
        JSONObject object = new JSONObject(msg);
        PendingIntent pendingIntent = null;
        String notificationTitle, smallContentText, smallContentInfo = "";
        int notificationImageResource = R.drawable.ic_noty_point, notificationID,
                uniquePendingId = (int) (System.currentTimeMillis() & 0xfffffff);

        SharedPreferences pref = getSharedPreferences("pref_notification", Activity.MODE_PRIVATE);

        Uri noty_sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        if (!TextUtils.isEmpty(pref.getString("notifications_new_message_ringtone", ""))) {
            noty_sound = Uri.parse(pref.getString("notifications_new_message_ringtone", ""));
        }

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSound(noty_sound)
                .setLights(0xff2ECC71, 300, 1000).setAutoCancel(Boolean.TRUE);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
            mBuilder.setCategory(Notification.CATEGORY_SOCIAL);

        if (pref.getBoolean("notifications_new_message_vibrate", true)) {
            mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
        }

        Intent activityIntent = new Intent();
        switch (NotificationType.getType(object.getInt(getString(R.string.field_gcm_msg_type)))) {
        case SHARE_POINTS:
            //user received points from contact
            String sender = object.getString(getString(R.string.field_gcm_name));
            int amount = object.getInt(getString(R.string.contact_send_amount));
            notificationTitle = getString(R.string.gcm_message_recieved_points);
            smallContentText = String.format(getString(R.string.gcm_message_recieved_points_content), sender,
                    amount);
            smallContentInfo = String.valueOf(amount);
            notificationImageResource = R.drawable.ic_noty_point;
            notificationID = getRandomInt(0, 50);

            mBuilder.setColor(getResources().getColor(R.color.alizarin));

            activityIntent.setClass(this, PointReceivedActivity.class);
            activityIntent.setAction(NOTIFICATION_ACTION_POINTS);
            activityIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg);

            TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
            stackBuilder.addParentStack(PointReceivedActivity.class);
            stackBuilder.addNextIntent(activityIntent);

            Intent broadcastIntent = new Intent(this, GraabyBroadcastReceiver.class);
            broadcastIntent.setAction(GraabyBroadcastReceiver.ACTION_THANK);
            broadcastIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg);
            broadcastIntent.putExtra(Helper.NOTIFICATIONID, notificationID);

            PendingIntent pendingBroadcastIntent = PendingIntent.getBroadcast(this, uniquePendingId,
                    broadcastIntent, 0);

            mBuilder.addAction(R.drawable.ic_action_accept, "Say thanks", pendingBroadcastIntent);

            pendingIntent = stackBuilder.getPendingIntent(uniquePendingId, PendingIntent.FLAG_ONE_SHOT);
            break;
        case TRANSACTION:
            //user made a transaction
            amount = object.getInt(getString(R.string.contact_send_amount));
            String outlet = object.getString(getString(R.string.field_business_name));
            notificationTitle = getString(R.string.gcm_message_transaction);
            smallContentText = String.format(getString(R.string.gcm_message_transaction_content), amount,
                    outlet);
            smallContentInfo = String.valueOf(amount);
            notificationImageResource = R.drawable.ic_noty_point;
            notificationID = getRandomInt(51, 100);

            mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(smallContentText));
            mBuilder.setColor(getResources().getColor(R.color.alizarin));

            activityIntent.setClass(this, PointReceivedActivity.class);
            activityIntent.setAction(NOTIFICATION_ACTION_TX);
            activityIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg);
            activityIntent.putExtra(Helper.NOTIFICATIONID, notificationID);

            pendingIntent = PendingIntent.getActivity(this, 0, activityIntent, PendingIntent.FLAG_ONE_SHOT);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                mBuilder.setCategory(Notification.CATEGORY_STATUS);
            break;
        case NEW_VOUCHER:
            //new marketplace voucher has appeared
            outlet = object.getString(getString(R.string.field_business_name));
            notificationTitle = getString(R.string.gcm_message_market);
            if (object.has("msg"))
                smallContentText = object.getString("msg") + " @ " + outlet;
            else
                smallContentText = String.format(getString(R.string.gcm_message_market_content), outlet);
            smallContentInfo = "";
            notificationImageResource = R.drawable.ic_gcm_discount;
            notificationID = NOTIFICATION_ID_NEW_MARKET;

            mBuilder.setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(String.format(getString(R.string.gcm_message_market_content), outlet)));
            mBuilder.setColor(getResources().getColor(R.color.sunflower));

            activityIntent.setClass(this, MarketActivity.class);
            activityIntent.setAction(NOTIFICATION_ACTION_NEW_DISCOUNT);
            activityIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg);
            activityIntent.putExtra(Helper.NOTIFICATIONID, NOTIFICATION_ID_NEW_MARKET);
            activityIntent.putExtra(Helper.MY_DISCOUNT_ITEMS_FLAG, false);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                mBuilder.setCategory(Notification.CATEGORY_PROMO);
            break;
        case NEW_FEED:
            notificationTitle = "New message";
            smallContentText = object.getString("msg");
            notificationImageResource = R.drawable.ic_noty_announcement;
            notificationID = NOTIFICATION_ID_FEED;

            activityIntent.setClass(this, FeedActivity.class);
            activityIntent.putExtra(Helper.NOTIFICATIONID, NOTIFICATION_ID_FEED);
            activityIntent.setAction(NOTIFICATION_ACTION_FEED);

            mBuilder.setColor(getResources().getColor(R.color.alizarin));

            pendingIntent = TaskStackBuilder.create(this).addNextIntentWithParentStack(activityIntent)
                    .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
            break;
        case THANK_CONTACT:
            //contact thanks you for sending points
            String thanksString = object.getString(getString(R.string.field_gcm_name));
            notificationTitle = getString(R.string.gcm_message_thanked);
            smallContentText = String.format(getString(R.string.gcm_message_thanked_small_content),
                    thanksString);
            mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(smallContentText));
            notificationImageResource = R.drawable.ic_noty_thank;
            notificationID = NOTIFICATION_ID_THANKED;
            mBuilder.setColor(getResources().getColor(R.color.belizehole));

            break;
        case CHECKIN:
            //checkin notification
            outlet = object.getString(getString(R.string.field_gcm_name));
            notificationTitle = getString(R.string.gcm_message_checkin_title);
            smallContentText = String.format(getString(R.string.gcm_message_checkin_small_content), outlet);
            notificationImageResource = R.drawable.ic_gcm_checkin;
            notificationID = NOTIFICATION_ID_CHECKIN;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                mBuilder.setCategory(Notification.CATEGORY_STATUS);
            mBuilder.setColor(getResources().getColor(R.color.wisteria));

            break;
        case INFO_NEEDED:
            notificationTitle = getString(R.string.gcm_message_meta_info_title);
            smallContentText = getString(R.string.gcm_message_meta_info_title);
            notificationImageResource = R.drawable.ic_noty_information;
            notificationID = NOTIFICATION_ID_INFO;

            mBuilder.setColor(getResources().getColor(R.color.emarald));

            activityIntent.setClass(this, ExtraInfoActivity.class);
            activityIntent.setAction(NOTIFICATION_ACTION_INFO);
            activityIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg);
            activityIntent.putExtra(Helper.NOTIFICATIONID, notificationID);

            pendingIntent = PendingIntent.getActivity(this, 0, activityIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            break;
        case NONE:
        default:
            notificationTitle = "";
            smallContentText = "";
            smallContentInfo = "";
            notificationID = 0;
        }

        if (pendingIntent == null)
            pendingIntent = PendingIntent.getActivity(this, 0, activityIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

        NotificationManager mNotificationManager = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);

        mBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), notificationImageResource))
                .setSmallIcon(R.drawable.ic_noty_graaby).setContentTitle(notificationTitle)
                .setContentText(smallContentText).setContentInfo(smallContentInfo)
                .setContentIntent(pendingIntent);

        mNotificationManager.notify(notificationID, mBuilder.build());
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.stanleyidesis.quotograph.api.controller.LWQNotificationControllerImpl.java

@Override
public void postSurveyNotification() {
    LWQApplication lwqApplication = LWQApplication.get();

    // Prepare PIs
    final String responseAction = lwqApplication.getString(R.string.action_survey_response);
    Intent neverIntent = new Intent(responseAction);
    neverIntent.setClass(lwqApplication, LWQReceiver.class); // I HATE YOU, PENDING INTENT
    neverIntent.setData(Uri.parse(String.valueOf(UserSurveyController.RESPONSE_NEVER)));
    Intent laterIntent = new Intent(responseAction);
    laterIntent.setData(Uri.parse(String.valueOf(UserSurveyController.RESPONSE_LATER)));
    laterIntent.setClass(lwqApplication, LWQReceiver.class);
    Intent okayIntent = new Intent(responseAction);
    okayIntent.setData(Uri.parse(String.valueOf(UserSurveyController.RESPONSE_OKAY)));
    okayIntent.setClass(lwqApplication, LWQReceiver.class);
    PendingIntent neverPI = PendingIntent.getBroadcast(lwqApplication, uniqueRequestCode++, neverIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    PendingIntent laterPI = PendingIntent.getBroadcast(lwqApplication, uniqueRequestCode++, laterIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    PendingIntent okayPI = PendingIntent.getBroadcast(lwqApplication, uniqueRequestCode++, okayIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(lwqApplication);
    notificationBuilder.setAutoCancel(true)
            .addAction(R.drawable.md_transparent, lwqApplication.getString(R.string.survey_never), neverPI)
            .addAction(R.drawable.md_transparent, lwqApplication.getString(R.string.survey_later), laterPI)
            .addAction(R.drawable.md_transparent, lwqApplication.getString(R.string.survey_okay), okayPI)
            .setCategory(Notification.CATEGORY_PROMO)
            .setColor(lwqApplication.getResources().getColor(R.color.palette_A100)).setContentIntent(okayPI)
            .setContentText(lwqApplication.getString(R.string.survey_cta))
            .setContentTitle(lwqApplication.getString(R.string.survey_title)).setDeleteIntent(laterPI)
            .setLights(lwqApplication.getResources().getColor(R.color.palette_A100), 500, 500).setOngoing(false)
            .setPriority(NotificationCompat.PRIORITY_MAX).setShowWhen(false).setSmallIcon(R.mipmap.ic_stat)
            .setTicker(lwqApplication.getString(R.string.survey_title)).setWhen(System.currentTimeMillis());

    NotificationManager notificationManager = (NotificationManager) LWQApplication.get()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIF_ID_SURVEY, notificationBuilder.build());
}