Android Open Source - appboy-android-sdk Appboy Broadcast Receiver

From Project

Back to project page appboy-android-sdk.


The source code is released under:

Copyright (c) 2014 Appboy, Inc. All rights reserved. * Use of source code or binaries contained within Appboy's Android SDK is permitted only to enable use of the Appboy platform by customers of Appb...

If you think the Android project appboy-android-sdk 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.appboy.sample;
//from   ww w .j  a v a 2 s .  c  o m
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import com.appboy.AppboyGcmReceiver;
import com.appboy.Constants;

public class AppboyBroadcastReceiver extends BroadcastReceiver {
  private static final String TAG = String.format("%s.%s", Constants.APPBOY_LOG_TAG_PREFIX, AppboyBroadcastReceiver.class.getName());
  public static final String SOURCE_KEY = "source";
  public static final String DESTINATION_VIEW = "destination";
  public static final String HOME = "home";
  public static final String FEED = "feed";
  public static final String FEEDBACK = "feedback";

  public void onReceive(Context context, Intent intent) {
    String packageName = context.getPackageName();
    String pushReceivedAction = packageName + ".intent.APPBOY_PUSH_RECEIVED";
    String notificationOpenedAction = packageName + ".intent.APPBOY_NOTIFICATION_OPENED";
    String action = intent.getAction();
    Log.d(TAG, String.format("Received intent with action %s", action));

    if (pushReceivedAction.equals(action)) {
      Log.d(TAG, "Received push notification.");
    } else if (notificationOpenedAction.equals(action)) {
      Bundle extras = new Bundle();
      extras.putString(DESTINATION_VIEW, FEED);
      extras.putString(AppboyGcmReceiver.CAMPAIGN_ID_KEY, intent.getStringExtra(AppboyGcmReceiver.CAMPAIGN_ID_KEY));

      // If a custom URI is defined, start an ACTION_VIEW intent pointing at the custom URI.
      // The intent returned from getStartActivityIntent() is placed on the back stack.
      // Otherwise, start the intent defined in getStartActivityIntent().
      if (intent.getStringExtra(Constants.APPBOY_PUSH_CUSTOM_URI_KEY) != null) {
        Intent uriIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(intent.getStringExtra(Constants.APPBOY_PUSH_CUSTOM_URI_KEY)));
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addNextIntent(getStartActivityIntent(context, extras));
      } else {
        context.startActivity(getStartActivityIntent(context, extras));
    } else {
      Log.d(TAG, String.format("Ignoring intent with unsupported action %s", action));

  private Intent getStartActivityIntent(Context context, Bundle extras) {
    Intent startActivityIntent = new Intent(context, DroidBoyActivity.class);
    startActivityIntent.putExtra(SOURCE_KEY, Constants.APPBOY);
    if (extras != null) {
    return startActivityIntent;


Java Source Code List