@SuppressWarnings("deprecation")
  @SuppressLint("NewApi")
  public static void showNotification(Intent intent, Context c) {
    if (context == null) {
      context = c;
    }
    NotificationManager nm =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Intent _intent = new Intent();

    /*if (hasAction) {
    	if (action.equalsIgnoreCase("View")) {
    		_intent = context.getPackageManager()
    				.getLaunchIntentForPackage(context.getPackageName());
    	}
    }*/
    _intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());

    int _icon = icon;
    String _message = message;
    int _badge = badge;
    long _time = time;
    String _action = action;

    if (intent != null) {
      _icon = intent.getIntExtra("icon", 0);
      _message = intent.getStringExtra("message");
      _badge = intent.getIntExtra("badge", 0);
      _time = intent.getLongExtra("time", new Date().getTime());
      _action = intent.getStringExtra("action");
    }

    Notification n = null;
    PendingIntent pi = PendingIntent.getActivity(context, 0, _intent, 0);
    if (Build.VERSION.SDK_INT >= 11) {
      Notification.Builder builder = new Notification.Builder(context);
      builder
          .setContentIntent(pi)
          .setSmallIcon(_icon)
          .setTicker(_message)
          .setNumber(_badge)
          .setWhen(_time)
          .setAutoCancel(true)
          .setContentTitle(_action)
          .setContentText(_message);
      n = builder.getNotification();
    } else {
      n = new Notification();
      n.contentIntent = pi;
      n.icon = android.R.drawable.ic_dialog_info;
      n.tickerText = _message;
      n.number = _badge;
      n.when = _time;
      n.flags |= Notification.FLAG_AUTO_CANCEL;
      n.setLatestEventInfo(context, _action, _message, pi);
    }

    nm.notify((int) (_time / 1000), n);
    showStatusBar();
  }
Example #2
0
  @SuppressWarnings("deprecation")
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notification = new Notification();
    notification.icon = android.R.drawable.stat_sys_download;
    // notification.icon=android.R.drawable.stat_sys_download_done;
    notification.tickerText = getString(R.string.app_name) + "下载";
    notification.when = System.currentTimeMillis();
    notification.defaults = Notification.DEFAULT_LIGHTS;
    // 设置任务栏中下载进程显示的views
    views = new RemoteViews(getPackageName(), R.layout.version_update);
    notification.contentView = views;
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
    notification.setLatestEventInfo(this, "", "", contentIntent);
    // 将下载任务添加到任务栏中
    nm.notify(notificationId, notification);

    myHandler = new MyHandler(Looper.myLooper(), this);

    // 初始化下载任务内容views
    Message message = myHandler.obtainMessage(3, 0);
    myHandler.sendMessage(message);

    // 启动线程�?��执行下载任务
    downFile(intent.getStringExtra("url"));
    return super.onStartCommand(intent, flags, startId);
  }
    /**
     * Constructor.
     *
     * <p>Automatically sets the when field to {@link System#currentTimeMillis()
     * System.currentTimeMillis()} and the audio stream to the {@link Notification#STREAM_DEFAULT}.
     *
     * @param context A {@link Context} that will be used to construct the RemoteViews. The Context
     *     will not be held past the lifetime of this Builder object.
     */
    public Builder(Context context) {
      mContext = context;

      // Set defaults to match the defaults of a Notification
      mNotification.when = System.currentTimeMillis();
      mNotification.audioStreamType = Notification.STREAM_DEFAULT;
      mPriority = PRIORITY_DEFAULT;
    }
 private void setUpNotificationRelative() {
   notification = new Notification();
   notification.when = System.currentTimeMillis();
   notification.defaults = Notification.DEFAULT_LIGHTS;
   notification.icon = android.R.drawable.stat_sys_download;
   notification.contentIntent =
       PendingIntent.getActivity(context, 0, new Intent(), PendingIntent.FLAG_CANCEL_CURRENT);
   notificationManager =
       (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
 }
 {
     mShowWhen = true;
     mActions = new ArrayList();
     mLocalOnly = false;
     mColor = 0;
     mVisibility = 0;
     mNotification = new Notification();
     mContext = context;
     mNotification.when = System.currentTimeMillis();
     mNotification.audioStreamType = -1;
     mPriority = 0;
     mPeople = new ArrayList();
 }
    private void updateUsbNotification() {
      if (mNotificationManager == null || !mUseUsbNotification) return;
      int id = 0;
      Resources r = mContext.getResources();
      if (mConnected) {
        if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_MTP)) {
          id = com.android.internal.R.string.usb_mtp_notification_title;
        } else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_PTP)) {
          id = com.android.internal.R.string.usb_ptp_notification_title;
        } else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_MASS_STORAGE)) {
          id = com.android.internal.R.string.usb_cd_installer_notification_title;
        } else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ACCESSORY)) {
          id = com.android.internal.R.string.usb_accessory_notification_title;
        } else {
          // There is a different notification for USB tethering so we don't need one here
          // if (!containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_RNDIS)) {
          //    Slog.e(TAG, "No known USB function in updateUsbNotification");
          // }
        }
      }
      if (id != mUsbNotificationId) {
        // clear notification if title needs changing
        if (mUsbNotificationId != 0) {
          mNotificationManager.cancelAsUser(null, mUsbNotificationId, UserHandle.ALL);
          mUsbNotificationId = 0;
        }
        if (id != 0) {
          CharSequence message = r.getText(com.android.internal.R.string.usb_notification_message);
          CharSequence title = r.getText(id);

          Notification notification = new Notification();
          notification.icon = com.android.internal.R.drawable.stat_sys_data_usb;
          notification.when = 0;
          notification.flags = Notification.FLAG_ONGOING_EVENT;
          notification.tickerText = title;
          notification.defaults = 0; // please be quiet
          notification.sound = null;
          notification.vibrate = null;
          notification.priority = Notification.PRIORITY_MIN;

          Intent intent =
              Intent.makeRestartActivityTask(
                  new ComponentName("com.android.settings", "com.android.settings.UsbSettings"));
          PendingIntent pi =
              PendingIntent.getActivityAsUser(mContext, 0, intent, 0, null, UserHandle.CURRENT);
          notification.setLatestEventInfo(mContext, title, message, pi);
          mNotificationManager.notifyAsUser(null, id, notification, UserHandle.ALL);
          mUsbNotificationId = id;
        }
      }
    }
  private Notification createNotification(String text) {
    Notification notification = new Notification();

    notification.icon = R.drawable.logo;
    notification.when = System.currentTimeMillis();

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;

    notification.defaults |= Notification.DEFAULT_LIGHTS;

    notification.ledARGB = Color.WHITE;
    notification.ledOnMS = 1500;
    notification.ledOffMS = 1500;
    notification.tickerText = text;

    return notification;
  }
Example #8
0
 public void sendNote(String title, String text, String dia_show) {
   // 通知显示
   NotificationManager noteman1 =
       (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
   Notification note1 = new Notification();
   note1.icon = R.mipmap.ic_launcher;
   note1.tickerText = title; // 翻动显示
   note1.when = System.currentTimeMillis();
   note1.defaults = Notification.DEFAULT_ALL; // 访问灯光、震动需要权限
   note1.flags = Notification.FLAG_AUTO_CANCEL; // 点击消失
   Intent intent = new Intent(context, ClockDialog.class); // 点击启动主程序
   // 添加数据//此处不必理会记录写入等问题,因为我已经取消了它的显示//使用它需要修改AnRing存储的传递模式
   intent.putExtra("method", ClockDialog.METHOD_NOTE_CLICK);
   intent.putExtra("text", dia_show);
   PendingIntent pend = PendingIntent.getActivity(context, 0, intent, 0);
   note1.setLatestEventInfo(context, title, text, pend); // 固定显示
   noteman1.notify(0, note1);
 }
 public static Notification createNotification(
     Context context,
     int iconId,
     int tickerTextResId,
     int contentTextResId,
     PendingIntent pendingIntent) {
   String tickerText = context.getString(tickerTextResId);
   String contentText = context.getString(contentTextResId);
   if (ApiHelper.getAPILevel() < 11) {
     Notification notification = new Notification();
     notification.tickerText = tickerText;
     notification.when = System.currentTimeMillis();
     //noinspection deprecation
     notification.icon = iconId;
     notification.contentIntent = pendingIntent;
     // Google removed setLatestEventInfo in sdk 23.
     //noinspection TryWithIdenticalCatches
     try {
       Method method =
           Notification.class.getMethod(
               "setLatestEventInfo",
               Context.class,
               CharSequence.class,
               CharSequence.class,
               PendingIntent.class);
       method.invoke(notification, context, tickerText, contentText, pendingIntent);
     } catch (NoSuchMethodException e) {
       Log.v(TAG, e.getMessage(), e);
     } catch (IllegalAccessException e) {
       Log.v(TAG, e.getMessage(), e);
     } catch (InvocationTargetException e) {
       Log.v(TAG, e.getMessage(), e);
     }
     return notification;
   } else if (ApiHelper.getAPILevel() < 16) {
     return Api11Helper.createNotification(
         context, iconId, tickerText, contentText, pendingIntent);
   } else {
     return Api16Helper.createNotification(
         context, iconId, tickerText, contentText, pendingIntent);
   }
 }
Example #10
0
 /**
  * This method can be overriden in order to create a foreground SpiceService. By default, it will
  * create a notification that can be used to set a spiceService to foreground (depending on the
  * versions of Android, the behavior is different : before ICS, no notification is shown, on ICS+,
  * a notification is shown with app icon). On Jelly Bean+, the notifiation only appears when
  * notification bar is expanded / pulled down.
  *
  * @return a notification used to tell user that the SpiceService is still running and processing
  *     requests.
  */
 @SuppressWarnings("deprecation")
 public Notification createDefaultNotification() {
   Notification notification = new Notification();
   if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH
       && android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
     notification.icon = getApplicationInfo().icon;
     // temporary fix https://github.com/octo-online/robospice/issues/200
     PendingIntent pendingIntent =
         PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0);
     notification.setLatestEventInfo(this, "", "", pendingIntent);
   } else {
     notification.icon = 0;
   }
   notification.tickerText = null;
   notification.when = System.currentTimeMillis();
   if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
     notification.priority = Notification.PRIORITY_MIN;
   }
   return notification;
 }
Example #11
0
 /** 显示软件下载对话框 */
 private void showDownloadNotification() {
   // 构造软件下载对话框
   if (notification == null)
     notification =
         new Notification(
             android.R.drawable.stat_sys_download,
             mContext.getString(R.string.soft_updating),
             System.currentTimeMillis());
   else {
     notification.icon = android.R.drawable.stat_sys_download;
     notification.tickerText = mContext.getString(R.string.soft_updating);
     notification.when = System.currentTimeMillis();
   }
   notification.flags |= Notification.FLAG_ONGOING_EVENT;
   RemoteViews contentView =
       new RemoteViews(mContext.getPackageName(), R.layout.download_notification);
   notification.contentView = contentView;
   contentView.setTextViewText(
       R.id.notificationTitle,
       mContext.getResources().getString(R.string.notify_downloading)
           + mContext.getString(R.string.theme_box_name));
   contentView.setTextViewText(R.id.notificationPercent, "0%");
   contentView.setProgressBar(R.id.notificationProgress, 100, 0, true);
   contentView.setViewVisibility(R.id.cancel, View.VISIBLE);
   Intent it = new Intent(mContext, UIStaticsReceiver.class);
   it.setAction("com.coco.personalCenter.stop.update");
   PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, it, 0);
   contentView.setOnClickPendingIntent(R.id.cancel, pendingIntent);
   Intent intent = new Intent();
   intent.putExtra("notifyID", id);
   PendingIntent contentIntent =
       PendingIntent.getActivity(
           mContext, (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
   notification.contentIntent = contentIntent;
   manager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
   manager.notify(id, notification);
   // 下载文件
   downloadApk();
   // cancel(cancelUpdate = true;
   // dialogIsShow = false;)
 }
  private Notification getNotifcation(String url) {
    Notification notification = null;
    if (notificationMap.get(url) == null) {
      notification = new Notification();
      notification.icon = android.R.drawable.stat_sys_download;
      // mNotification.tickerText = mContext.getString(R.string.app_name)
      // + "更新";
      notification.when = System.currentTimeMillis();
      notification.defaults = Notification.DEFAULT_LIGHTS;
      Intent intent =
          new Intent(App.getContext().getApplicationContext(), App.getContext().getClass());
      PendingIntent contentIntent =
          PendingIntent.getActivity(App.getContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
      notification.contentIntent = contentIntent;
      notificationMap.put(url, notification);
    } else {
      notification = notificationMap.get(url);
    }

    return notification;
  }
    private void adjustStatusBarCarModeLocked() {
        final Context context = getContext();
        if (mStatusBarManager == null) {
            mStatusBarManager = (StatusBarManager)
                    context.getSystemService(Context.STATUS_BAR_SERVICE);
        }

        // Fear not: StatusBarManagerService manages a list of requests to disable
        // features of the status bar; these are ORed together to form the
        // active disabled list. So if (for example) the device is locked and
        // the status bar should be totally disabled, the calls below will
        // have no effect until the device is unlocked.
        if (mStatusBarManager != null) {
            mStatusBarManager.disable(mCarModeEnabled
                ? StatusBarManager.DISABLE_NOTIFICATION_TICKER
                : StatusBarManager.DISABLE_NONE);
        }

        if (mNotificationManager == null) {
            mNotificationManager = (NotificationManager)
                    context.getSystemService(Context.NOTIFICATION_SERVICE);
        }

        if (mNotificationManager != null) {
            if (mCarModeEnabled) {
                Intent carModeOffIntent = new Intent(context, DisableCarModeActivity.class);

                Notification n = new Notification();
                n.icon = R.drawable.stat_notify_car_mode;
                n.defaults = Notification.DEFAULT_LIGHTS;
                n.flags = Notification.FLAG_ONGOING_EVENT;
                n.when = 0;
                n.color = context.getResources().getColor(
                        com.android.internal.R.color.system_notification_accent_color);
                n.setLatestEventInfo(
                        context,
                        context.getString(R.string.car_mode_disable_notification_title),
                        context.getString(R.string.car_mode_disable_notification_message),
                        PendingIntent.getActivityAsUser(context, 0, carModeOffInte
    private void updateAdbNotification() {
      if (mNotificationManager == null) return;
      final int id = com.android.internal.R.string.adb_active_notification_title;
      if (mAdbEnabled && mConnected) {
        if ("0".equals(SystemProperties.get("persist.adb.notify"))
            || Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.ADB_NOTIFY, 1)
                == 0) return;

        if (!mAdbNotificationShown) {
          Resources r = mContext.getResources();
          CharSequence title = r.getText(id);
          CharSequence message =
              r.getText(com.android.internal.R.string.adb_active_notification_message);

          Notification notification = new Notification();
          notification.icon = com.android.internal.R.drawable.stat_sys_adb;
          notification.when = 0;
          notification.flags = Notification.FLAG_ONGOING_EVENT;
          notification.tickerText = title;
          notification.defaults = 0; // please be quiet
          notification.sound = null;
          notification.vibrate = null;
          notification.priority = Notification.PRIORITY_LOW;

          Intent intent =
              Intent.makeRestartActivityTask(
                  new ComponentName(
                      "com.android.settings", "com.android.settings.DevelopmentSettings"));
          PendingIntent pi =
              PendingIntent.getActivityAsUser(mContext, 0, intent, 0, null, UserHandle.CURRENT);
          notification.setLatestEventInfo(mContext, title, message, pi);
          mAdbNotificationShown = true;
          mNotificationManager.notifyAsUser(null, id, notification, UserHandle.ALL);
        }
      } else if (mAdbNotificationShown) {
        mAdbNotificationShown = false;
        mNotificationManager.cancelAsUser(null, id, UserHandle.ALL);
      }
    }
Example #15
0
  // Display the topbar notification
  private void showNotification(String text, Intent it) {
    Notification n = new Notification();

    n.flags |= Notification.FLAG_SHOW_LIGHTS;
    n.flags |= Notification.FLAG_AUTO_CANCEL;

    // n.defaults = Notification.DEFAULT_ALL;

    n.icon = R.drawable.ic_launcher;
    n.when = System.currentTimeMillis();
    // n.sound = Uri.parse("android.resource://" + this.getPackageName() +"/" + R.raw.push);
    n.vibrate = null;
    n.tickerText = text;

    // Simply open the parent activity
    PendingIntent pi = PendingIntent.getActivity(this, 0, it, PendingIntent.FLAG_UPDATE_CURRENT);

    // Change the name of the notification here
    n.setLatestEventInfo(this, NOTIF_TITLE, text, pi);

    mNotifMan.notify(NOTIF_CONNECTED, n);
  }
  private void sendNotification(String msg, Context context) {
    NotificationManager mNotificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification();
    // notification = new
    // Notification.Builder(context).setContentTitle("Reminder").setContentText(msg).setSmallIcon(android.R.drawable.stat_sys_warning).build();   // required api 11
    // notification.icon = android.R.drawable.stat_notify_sync;
    notification.icon = android.R.drawable.stat_sys_warning;
    notification.tickerText = "Reminder";
    notification.when = System.currentTimeMillis();
    // notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
    notification.flags = Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_AUTO_CANCEL;
    notification.defaults |= Notification.DEFAULT_SOUND;
    //  notification.defaults |= Notification.DEFAULT_VIBRATE;
    // notification.vibrate = new long[]{100, 500, 100, 500, 100};

    // #ff1900 (dark orange)
    // #ff3300 (web-safe orange)
    // #ff2d00 (medium orange)
    // #ff4000 (medium orange)
    // #ff5300 (light orange)
    notification.ledARGB = Color.parseColor("#FF4000");
    notification.ledOffMS = 50;
    notification.ledOnMS = 500;

    // Intent intent = new Intent(this, MainActivity.class);
    notification.setLatestEventInfo(
        context, "Reminder", msg, PendingIntent.getActivity(context, 0, new Intent(), 0));
    // PendingIntent.getActivity(context, 0, null, 0));
    // PendingIntent.getActivity(this, 1, intent, 0));
    mNotificationManager.notify("test" + System.currentTimeMillis(), 100, notification);

    // Vibrate - phone may vibrate on notification even if vibrate not set in app
    if (isVibrateSet(context)) {
      Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
      vibrator.vibrate(1000);
    }
  }
Example #17
0
  /** Sets the media storage notification. */
  private synchronized void setMediaStorageNotification(
      int titleId,
      int messageId,
      int icon,
      boolean visible,
      boolean dismissable,
      PendingIntent pi) {

    if (!visible && mMediaStorageNotification == null) {
      return;
    }

    NotificationManager notificationManager =
        (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);

    if (notificationManager == null) {
      return;
    }

    if (mMediaStorageNotification != null && visible) {
      /*
       * Dismiss the previous notification - we're about to
       * re-use it.
       */
      final int notificationId = mMediaStorageNotification.icon;
      notificationManager.cancel(notificationId);
    }

    if (visible) {
      Resources r = Resources.getSystem();
      CharSequence title = r.getText(titleId);
      CharSequence message = r.getText(messageId);

      if (mMediaStorageNotification == null) {
        mMediaStorageNotification = new Notification();
        mMediaStorageNotification.when = 0;
      }

      mMediaStorageNotification.defaults &= ~Notification.DEFAULT_SOUND;

      if (dismissable) {
        mMediaStorageNotification.flags = Notification.FLAG_AUTO_CANCEL;
      } else {
        mMediaStorageNotification.flags = Notification.FLAG_ONGOING_EVENT;
      }

      mMediaStorageNotification.tickerText = title;
      if (pi == null) {
        Intent intent = new Intent();
        pi = PendingIntent.getBroadcastAsUser(mContext, 0, intent, 0, UserHandle.CURRENT);
      }

      mMediaStorageNotification.icon = icon;
      mMediaStorageNotification.color =
          mContext
              .getResources()
              .getColor(com.android.internal.R.color.system_notification_accent_color);
      mMediaStorageNotification.setLatestEventInfo(mContext, title, message, pi);
      mMediaStorageNotification.visibility = Notification.VISIBILITY_PUBLIC;
      mMediaStorageNotification.category = Notification.CATEGORY_SYSTEM;
    }

    final int notificationId = mMediaStorageNotification.icon;
    if (visible) {
      notificationManager.notifyAsUser(
          null, notificationId, mMediaStorageNotification, UserHandle.ALL);
    } else {
      notificationManager.cancelAsUser(null, notificationId, UserHandle.ALL);
    }
  }
Example #18
0
  /** Sets the USB storage notification. */
  private synchronized void setUsbStorageNotification(
      int titleId, int messageId, int icon, boolean sound, boolean visible, PendingIntent pi) {

    if (!visible && mUsbStorageNotification == null) {
      return;
    }

    NotificationManager notificationManager =
        (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);

    if (notificationManager == null) {
      return;
    }

    if (visible) {
      Resources r = Resources.getSystem();
      CharSequence title = r.getText(titleId);
      CharSequence message = r.getText(messageId);

      if (mUsbStorageNotification == null) {
        mUsbStorageNotification = new Notification();
        mUsbStorageNotification.icon = icon;
        mUsbStorageNotification.when = 0;
      }

      if (sound) {
        mUsbStorageNotification.defaults |= Notification.DEFAULT_SOUND;
      } else {
        mUsbStorageNotification.defaults &= ~Notification.DEFAULT_SOUND;
      }

      mUsbStorageNotification.flags = Notification.FLAG_ONGOING_EVENT;

      mUsbStorageNotification.tickerText = title;
      if (pi == null) {
        Intent intent = new Intent();
        pi = PendingIntent.getBroadcastAsUser(mContext, 0, intent, 0, UserHandle.CURRENT);
      }
      mUsbStorageNotification.color =
          mContext
              .getResources()
              .getColor(com.android.internal.R.color.system_notification_accent_color);
      mUsbStorageNotification.setLatestEventInfo(mContext, title, message, pi);
      mUsbStorageNotification.visibility = Notification.VISIBILITY_PUBLIC;
      mUsbStorageNotification.category = Notification.CATEGORY_SYSTEM;

      final boolean adbOn =
          1
              == Settings.Global.getInt(
                  mContext.getContentResolver(), Settings.Global.ADB_ENABLED, 0);

      if (POP_UMS_ACTIVITY_ON_CONNECT && !adbOn) {
        // Pop up a full-screen alert to coach the user through enabling UMS. The average
        // user has attached the device to USB either to charge the phone (in which case
        // this is harmless) or transfer files, and in the latter case this alert saves
        // several steps (as well as subtly indicates that you shouldn't mix UMS with other
        // activities on the device).
        //
        // If ADB is enabled, however, we suppress this dialog (under the assumption that a
        // developer (a) knows how to enable UMS, and (b) is probably using USB to install
        // builds or use adb commands.
        // Modify by GIONEE
        // mUsbStorageNotification.fullScreenIntent = pi;
      }
    }

    final int notificationId = mUsbStorageNotification.icon;
    if (visible) {
      notificationManager.notifyAsUser(
          null, notificationId, mUsbStorageNotification, UserHandle.CURRENT);
    } else {
      notificationManager.cancelAsUser(null, notificationId, UserHandle.CURRENT);
    }
  }
  /** Sets the media storage notification. */
  private synchronized void setMediaStorageNotification(
      int titleId,
      int messageId,
      int icon,
      boolean visible,
      boolean dismissable,
      PendingIntent pi) {

    if (!visible && mMediaStorageNotification == null) {
      return;
    }

    NotificationManager notificationManager =
        (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);

    if (notificationManager == null) {
      return;
    }

    if (mMediaStorageNotification != null && visible) {
      /*
       * Dismiss the previous notification - we're about to
       * re-use it.
       */
      final int notificationId = mMediaStorageNotification.icon;
      notificationManager.cancel(notificationId);
    }

    if (visible) {
      Resources r = Resources.getSystem();
      CharSequence title = r.getText(titleId);
      CharSequence message = r.getText(messageId);

      if (mMediaStorageNotification == null) {
        mMediaStorageNotification = new Notification();
        mMediaStorageNotification.when = 0;
      }

      mMediaStorageNotification.defaults &= ~Notification.DEFAULT_SOUND;

      if (dismissable) {
        mMediaStorageNotification.flags = Notification.FLAG_AUTO_CANCEL;
      } else {
        mMediaStorageNotification.flags = Notification.FLAG_ONGOING_EVENT;
      }

      mMediaStorageNotification.tickerText = title;
      if (pi == null) {
        Intent intent = new Intent();
        pi = PendingIntent.getBroadcast(mContext, 0, intent, 0);
      }

      mMediaStorageNotification.icon = icon;
      mMediaStorageNotification.setLatestEventInfo(mContext, title, message, pi);
    }

    final int notificationId = mMediaStorageNotification.icon;
    if (visible) {
      notificationManager.notify(notificationId, mMediaStorageNotification);
    } else {
      notificationManager.cancel(notificationId);
    }
  }
  // Checks the database then creates and pushes notifications and alerts to the android.
  public void showNotification() {
    String s;
    count = 0;

    // Load the shared preferences
    LoadPreferences();

    if (notifOn) {
      // Open the database adapter
      adapter.open();

      s = adapter.fetchAll(5);
      count = Integer.parseInt(s.substring(2));

      // BROKEN: fetch all of the items about to expire
      // l = new ArrayList <Item> (adapter.fetchAll());

      // Close the database adapter
      adapter.close();

      // If notifications are on
      if (count > 0) {
        Notification note =
            new Notification(R.drawable.icon, "Food Expiring", System.currentTimeMillis());

        PendingIntent in =
            PendingIntent.getActivity(this, 0, new Intent(this, PantryProtectorActivity.class), 0);

        note.icon = R.drawable.icon;
        note.tickerText = "Food Expiring";
        note.when = System.currentTimeMillis();
        note.number = count;
        note.flags |= Notification.FLAG_AUTO_CANCEL;

        // Add flashing to the notifications
        if (flashOn && s.charAt(1) == '1') {
          // add lights to notifications
          if (debug) Log.i("DEBUG", ">>>>> Flashing. >>>>>");
          note.flags |= Notification.FLAG_SHOW_LIGHTS;
          note.ledARGB = Color.CYAN;
          note.ledOnMS = 500;
          note.ledOffMS = 500;
        }

        // Add vibration to notifications
        if (vibrateOn && s.charAt(0) == '1') {
          // add vibration to notifications
          if (debug) Log.i("DEBUG", ">>>>> ViBrAtInG. >>>>>");
          note.vibrate = new long[] {100, 200, 200, 200, 200, 200, 1000, 200, 200, 200, 1000, 200};
        }

        note.setLatestEventInfo(
            this, "Items are about to expire!", count + " items are about to expire!", in);

        notifManager.notify(NOTIF_ID, note);
      }

      // Debug statement for checking proper data flow
      if (debug && (date.getHours() != mHour || date.getMinutes() != mMinute)) {
        System.out.println(
            "Original Schedule: "
                + date.getDay()
                + ","
                + date.getHours()
                + ":"
                + date.getMinutes());
        date = new Date();
        date.setHours(mHour);
        date.setMinutes(mMinute);
        timer.cancel();
        System.out.println(
            "Changed Schedule: " + date.getDay() + "," + date.getHours() + ":" + date.getMinutes());
        startschedule();
      }
    }
  }
  private void _getPositionUpdate() {

    double lat = 0.0, lon = 0.0;

    String latlonString;

    // Log.i(getClass().getSimpleName(), " In getPositionUpdate ");

    Location currentLocation = fulfillerLocManager.getLastKnownLocation(hdLocProvider);

    if (currentLocation != null) {
      lat = currentLocation.getLatitude();
      lon = currentLocation.getLongitude();

      latlonString = "\n>>Lat: " + lat + " Lon: " + lon;
    } else {

      latlonString = "\n!!Current location info not available!! ";
    }

    // Log.i(getClass().getSimpleName(), latlonString);

    if (currentLocation == null) {

      HunyDewZLogger.write(this, "_getPositionUpdate", "Current location info not available");

      return;
    }

    HunyDewZLogger.write(
        this,
        "_getPositionUpdate",
        latlonString + " >> prevLat: " + prevLat + " prevLon: " + prevLon);

    // before we do any processing disable the timer on the fulfiller service
    // shutdownFulfillerService();

    int iPrevCurrentLat = Double.compare(lat, prevLat);

    int iPrevCurrentLon = Double.compare(lon, prevLon);

    if ((iPrevCurrentLat == 0) && (iPrevCurrentLon == 0)) {
      // position has not changed since the last check so no
      // further processing is required so return
      return;
    }

    // if (hdDBAdapterLoca.isDirty()) {

    // hdDBAdapterLoca.open();

    // hdDBAdapterLoca.close();

    //	hdDBAdapterLoca.removeDirtyFlag();
    // }

    prevLat = lat;
    prevLon = lon;

    String currentLocaName = locaStore.getLocaName(lat, lon);
    String taskLocaName;
    if (currentLocaName != null) {

      Log.i(getClass().getSimpleName(), currentLocaName);

      HunyDewZLogger.write(
          getApplicationContext(), "_getPositionUpdate", "Known Location: " + currentLocaName);

      hdDBAdapterTask = new HunyDewDBAdapterTask(this);

      hdDBAdapterTask.open();

      hdTaskListCursor = hdDBAdapterTask.getAllHDTaskItemsCursor();

      while (hdTaskListCursor.moveToNext()) {

        taskLocaName = hdTaskListCursor.getString(hdDBAdapterTask.COL_TASK_LOCA_NAME);

        if (currentLocaName.equalsIgnoreCase(taskLocaName) == true) {

          String taskName = hdTaskListCursor.getString(hdDBAdapterTask.COL_TASK_NAME);

          Log.i(getClass().getSimpleName(), taskName);

          HunyDewZLogger.write(
              getApplicationContext(), "_getPositionUpdate", "Found Task: " + taskName);

          // now prepare the Notification
          // Get a reference to the Notification Manager

          String svcName = Context.NOTIFICATION_SERVICE;
          NotificationManager notiMgr = (NotificationManager) getSystemService(svcName);

          Context context = getApplication();
          String expandedText = taskName;
          String expandedTtitle = getResources().getText(R.string.atLoca) + taskLocaName;

          Intent startActivityIntent =
              new Intent(HunyDooFulfillerService.this, HunyDewAAStartsHere.class);

          PendingIntent launchIntent =
              PendingIntent.getActivity(context, 0, startActivityIntent, 0);

          boolean isDebugEmulator = HunyDewUtils.signedWithDebugKey(this, this.getClass());
          if (isDebugEmulator == false) {
            hdLocaReachedNotification.defaults |= Notification.DEFAULT_SOUND;
            hdLocaReachedNotification.defaults |= Notification.DEFAULT_LIGHTS;
            hdLocaReachedNotification.defaults |= Notification.DEFAULT_VIBRATE;
            hdLocaReachedNotification.audioStreamType = AudioManager.STREAM_NOTIFICATION;

            // Repeat audio until the user responds
            hdLocaReachedNotification.flags |= Notification.FLAG_INSISTENT;

            // Flashing Lights
            hdLocaReachedNotification.ledARGB = 0xff00ff00;
            hdLocaReachedNotification.ledOnMS = 300;
            hdLocaReachedNotification.ledOffMS = 1000;
            hdLocaReachedNotification.flags |= Notification.FLAG_SHOW_LIGHTS;
          } else {
            hdLocaReachedNotification.defaults |= Notification.DEFAULT_SOUND;
          }

          hdLocaReachedNotification.setLatestEventInfo(
              context, expandedTtitle, expandedText, launchIntent);

          hdLocaReachedNotification.when = java.lang.System.currentTimeMillis();

          notiMgr.notify(LOCA_REACHJED_NOTIFICATION_ID, hdLocaReachedNotification);

          HunyDewZLogger.write(
              getApplicationContext(), "_getPositionUpdate", expandedText + expandedTtitle);

          // Toast AALocaToast = Toast .makeText(getApplicationContext(), expandedTtitle,
          // Toast.LENGTH_LONG);

          // AALocaToast.setGravity(Gravity.TOP, 0, 0);

          // AALocaToast.show();

          break;
        }
      }

      hdDBAdapterTask.close();
    }

    // now that we have a location name verify if this name exists in the
    // TaskList

    // now that we are done with chores start it again
    // startFulfillerService();
  }
 public void __constructor__(int icon, CharSequence tickerText, long when) {
   realNotification.icon = icon;
   realNotification.tickerText = tickerText;
   realNotification.when = when;
 }
 public mVisibility setWhen(long l)
 {
     mNotification.when = l;
     return this;
 }
 public Builder setWhen(long when) {
   mNotification.when = when;
   return this;
 }