@Override
  public void onReceive(final Context context, final Intent intent) {
    if (com.twofortyfouram.locale.Intent.ACTION_FIRE_SETTING.equals(intent.getAction())) {
      // fetch this for later, we may need it in case we change things
      // around and we need to know what version of the code they were
      // running when they saved the action
      int bundleVersionCode = intent.getIntExtra(Constants.BUNDLE_EXTRA_INT_VERSION_CODE, 1);

      String title = intent.getStringExtra(Constants.BUNDLE_EXTRA_STRING_TITLE);
      String body = intent.getStringExtra(Constants.BUNDLE_EXTRA_STRING_BODY);
      sendAlertToPebble(context, bundleVersionCode, title, body);
    }
  }
  /**
   * @param context {@inheritDoc}.
   * @param intent the incoming {@link com.twofortyfouram.locale.Intent#ACTION_FIRE_SETTING} Intent.
   *     This should contain the {@link com.twofortyfouram.locale.Intent#EXTRA_BUNDLE} that was
   *     saved by {@link EditActivity} and later broadcast by Locale.
   */
  @Override
  public void onReceive(final Context context, final Intent intent) {
    /*
     * Always be sure to be strict on input parameters! A malicious third-party app could always send an empty or otherwise
     * malformed Intent. And since Locale applies settings in the background, the plug-in definitely shouldn't crash in the
     * background.
     */

    Log.d(
        Constants.LOG_TAG,
        "FireReceiver.onReceive(): received intent, action='" + intent.getAction() + "'");

    /*
     * Locale guarantees that the Intent action will be ACTION_FIRE_SETTING
     */
    if (com.twofortyfouram.locale.Intent.ACTION_FIRE_SETTING.equals(intent.getAction())) {
      /*
       * A hack to prevent a private serializable classloader attack
       */
      BundleScrubber.scrub(intent);
      BundleScrubber.scrub(intent.getBundleExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE));

      final Bundle bundle = intent.getBundleExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE);

      /*
       * Final verification of the plug-in Bundle before firing the setting.
       */
      if (PluginBundleManager.isBundleValid(bundle)) {
        if (Constants.IS_LOGGABLE) {
          Log.d(Constants.LOG_TAG, "sending notification"); // $NON-NLS-1$
        }

        final String type = bundle.getString(PluginBundleManager.BUNDLE_EXTRA_STRING_TYPE);

        if (type.equals("notification")) {
          Intent broadcast = new Intent("org.metawatch.manager.NOTIFICATION");
          Bundle b = new Bundle();
          b.putString("title", bundle.getString(PluginBundleManager.BUNDLE_EXTRA_STRING_TITLE));
          b.putString("text", bundle.getString(PluginBundleManager.BUNDLE_EXTRA_STRING_MESSAGE));
          b.putBoolean(
              "sticky", bundle.getBoolean(PluginBundleManager.BUNDLE_EXTRA_BOOLEAN_STICKY, true));

          if (bundle.getBoolean(PluginBundleManager.BUNDLE_EXTRA_BOOLEAN_VIBRATE, false)) {
            b.putInt("vibrate_on", bundle.getInt(PluginBundleManager.BUNDLE_EXTRA_INT_VIBRATE_ON));
            b.putInt(
                "vibrate_off", bundle.getInt(PluginBundleManager.BUNDLE_EXTRA_INT_VIBRATE_OFF));
            b.putInt(
                "vibrate_cycles",
                bundle.getInt(PluginBundleManager.BUNDLE_EXTRA_INT_VIBRATE_CYCLES));
          }

          broadcast.putExtras(b);

          context.sendBroadcast(broadcast);
        } else if (type.equals("widget")) {
          final String icon = bundle.getString(PluginBundleManager.BUNDLE_EXTRA_STRING_WIDGET_ICON);
          final String widgetId =
              bundle.getString(PluginBundleManager.BUNDLE_EXTRA_STRING_WIDGET_ID);
          final String widgetLabel =
              bundle.getString(PluginBundleManager.BUNDLE_EXTRA_STRING_WIDGET_LABEL);

          createAndSendWidget(context, icon, widgetId, widgetLabel);
          cacheWidget(context, icon, widgetId, widgetLabel);

          if (bundle.getBoolean(PluginBundleManager.BUNDLE_EXTRA_BOOLEAN_VIBRATE, false)) {
            Intent broadcast = new Intent("org.metawatch.manager.VIBRATE");
            Bundle b = new Bundle();

            b.putInt("vibrate_on", bundle.getInt(PluginBundleManager.BUNDLE_EXTRA_INT_VIBRATE_ON));
            b.putInt(
                "vibrate_off", bundle.getInt(PluginBundleManager.BUNDLE_EXTRA_INT_VIBRATE_OFF));
            b.putInt(
                "vibrate_cycles",
                bundle.getInt(PluginBundleManager.BUNDLE_EXTRA_INT_VIBRATE_CYCLES));

            broadcast.putExtras(b);
            context.sendBroadcast(broadcast);
          }
        }

      } else {
        if (Constants.IS_LOGGABLE) {
          Log.d(Constants.LOG_TAG, "bundle invalid"); // $NON-NLS-1$
        }
      }

    } else if (intent.getAction().equals("org.metawatch.manager.REFRESH_WIDGET_REQUEST")) {
      Bundle bundle = intent.getExtras();
      boolean getPreviews = bundle.containsKey("org.metawatch.manager.get_previews");
      if (getPreviews) {
        Log.d(Constants.LOG_TAG, "get widget previews");

        File cacheDir = context.getCacheDir();

        File[] files = cacheDir.listFiles();

        for (File file : files) {
          FileInputStream fis;
          try {
            fis = new FileInputStream(file);
            StringBuffer fileContent = new StringBuffer("");

            byte[] buffer = new byte[1024];
            while ((fis.read(buffer)) != -1) {
              fileContent.append(new String(buffer));
            }

            String data = fileContent.toString();
            Log.d(Constants.LOG_TAG, "data: " + data);

            String[] sections = data.split("\\|");
            if (sections.length == 3) {
              createAndSendWidget(context, sections[0], sections[1], sections[2]);
            }
          } catch (FileNotFoundException e) {
          } catch (IOException e) {
          }
        }
      }
    }
  }