public void startNotifyDay(Context context, boolean vibrate) {
    int icon = R.drawable.ic_launcher; // 通知图标

    CharSequence tickerText = context.getString(R.string.fire_wall_open_fail_sysboot); // 状态栏(Status
    // Bar)显示的通知文本提示

    long when = System.currentTimeMillis(); // 通知产生的时间,会在通知信息里显示

    Notification notification = new Notification(icon, tickerText, when);
    if (vibrate) {
      long[] tVibrate = {0, 100, 200, 300};
      notification.vibrate = tVibrate;
    }
    // 设置跳转界面
    Intent intent = new Intent(context, WindowNotifyDialog.class);
    Bundle choosetab = new Bundle();
    choosetab.putInt("TAB", 3);
    intent.putExtras(choosetab);
    // 获得PendingIntent
    PendingIntent pi = PendingIntent.getActivity(context, 3, intent, 0);
    // 发出通知
    notification.setLatestEventInfo(
        context,
        context.getString(R.string.spearheadnotify),
        context.getString(R.string.fire_wall_open_fail_sysboot_set),
        pi);
    mNotificationManager.notify(FIREWALL_OPEN_FAIL_ID, notification);
  }
Example #2
0
  private void handleMessage(final Context context, Intent intent) {
    // push를 사용 안할 경우 메시지가 오더라도 무시 함.
    SharedPreferences preferences = context.getSharedPreferences("pushPref", Activity.MODE_PRIVATE);
    boolean isPushEnable = preferences.getBoolean("isPushEnable", true);
    if (!isPushEnable) {
      Logger.d("handleMessage", "isPushEnable : " + isPushEnable);
      return;
    }

    // 화면을 켬
    pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    wl =
        pm.newWakeLock(
            PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "bbbb");
    wl.acquire();

    Log.i("handleMessage", "------------ COME MESSAGE: " + pushKey);
    // TODO Auto-generated method stub
    String count = intent.getExtras().getString("badge");
    String message = intent.getExtras().getString("message");
    // String collaspe_key = intent.getExtras().getString("collaspe_key");

    Log.i("handleMessage", "------------ COME MESSAGE: " + message + ", " + count);

    Notification notification =
        new Notification(
            RUtil.getDrawableR(context, "app_icon"), message, System.currentTimeMillis());

    // notiId
    int notiID = (int) System.currentTimeMillis();
    // TODO 현재는 시작 화면으로 가게 했지만 추후 수정해야함.
    String title = PushManager.getInstance().getNotiMessage(PushManager.MESSAGE_TITLE);
    Intent in = new Intent(Intent.ACTION_MAIN);
    in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    in.addCategory(Intent.CATEGORY_LAUNCHER);
    in.setComponent(new ComponentName(context, DummyActivity.class));
    in.putExtra("push", message);
    in.putExtra("push_noti_id", notiID);
    PendingIntent pi =
        PendingIntent.getActivity(
            context, notiID, in, Intent.FLAG_ACTIVITY_NEW_TASK | PendingIntent.FLAG_ONE_SHOT);
    notification.setLatestEventInfo(context, title, message, pi);
    notification.flags |= Notification.FLAG_AUTO_CANCEL; // 선택시 자동삭제

    NotificationManager nm =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    // 전체 제거 고려
    if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
      notification.defaults |= android.app.Notification.DEFAULT_SOUND;
    } else {
      // 진동 효과 구성
      long[] vibrate = {1000, 1000, 1000, 1000, 1000};
      notification.vibrate = vibrate;
    }
    // nm.notify(PushManager.PUSH_MESSAGE, notification);
    nm.notify(notiID, notification);
    run.run();
  }
  private void showNotificationExr(
      Context context, int statusBarIconID, String string, boolean showIconOnly) {
    // This is who should be launched if the user selects our notification.
    Intent contentIntent = new Intent(context, WelbingActivityExercise.class);

    Intent targetIntent = new Intent(context, WellbeingExReminderAlert.class);
    targetIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    // choose the ticker text
    String tickerText = "Seva60Plus";

    Notification n = new Notification(R.drawable.icon, "Seva60Plus", System.currentTimeMillis());

    PendingIntent appIntent = PendingIntent.getActivity(context, 0, contentIntent, 0);

    n.setLatestEventInfo(context, "WELBING", "DID YOU EXERCISE TODAY ?", appIntent);

    // n.sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE +
    // "://com.seva60plus.seva60plus/raw/ex_sound");
    n.defaults |= Notification.DEFAULT_LIGHTS;
    n.flags |= Notification.FLAG_AUTO_CANCEL;
    n.flags |= Notification.FLAG_INSISTENT;

    long[] vibrate = {0, 500, 500, 500};
    n.vibrate = vibrate;

    // mNotificationManager.notify(YOURAPP_NOTIFICATION_ID, n);

    context.startActivity(targetIntent);
  }
  private void showNotification(String title, String note, boolean isTaskComplete) {

    Notification notification =
        new Notification(R.drawable.liltomato, null, System.currentTimeMillis());
    notification.flags = Notification.FLAG_ONGOING_EVENT;

    if (isTaskComplete) {

      notification = new Notification(R.drawable.liltomato_red, null, System.currentTimeMillis());
      notification.flags = Notification.FLAG_ONGOING_EVENT;
      String ringtone = taskDatabaseMap.getPreferences().getRingtone();
      if (ringtone == null) {
        ringtone =
            "android.resource://"
                + getApplication().getPackageName()
                + "/"
                + R.raw.freesoundprojectdotorg_32568__erh__indian_brass_pestle;
      }

      notification.sound = Uri.parse(ringtone);

      if (taskDatabaseMap.getPreferences().notifyPhoneVibrate()) {
        notification.vibrate = new long[] {0, 100, 200, 300};
      }

      notification.tickerText = title;
      notification.defaults |= Notification.DEFAULT_LIGHTS;
    }

    PendingIntent contentIntent =
        PendingIntent.getActivity(this, 0, new Intent(this, TaskBrowserActivity.class), 0);
    notification.setLatestEventInfo(this, title, note, contentIntent);
    notificationManager.notify(NOTIFICATION_ID, notification);
  }
Example #5
0
  public AppNotification(Context context, String title, String content, int drawable) {
    manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(drawable, title, System.currentTimeMillis());
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    Intent notificationIntent = new Intent();
    PendingIntent pedingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.vibrate = new long[] {0, 100, 200, 300};
    // notification.setLatestEventInfo(context, title, content, pedingIntent);

    manager.notify(drawable, notification);
  }
  public void notifyMe(View v) {
    Notification note =
        new Notification(
            R.drawable.stat_notify_chat, "Status message!", System.currentTimeMillis());
    PendingIntent i = PendingIntent.getActivity(this, 0, new Intent(this, NotifyMessage.class), 0);

    note.setLatestEventInfo(this, "Notification Title", "This is the notification message", i);
    note.number = ++count;
    note.vibrate = new long[] {500L, 200L, 200L, 500L};
    note.flags |= Notification.FLAG_AUTO_CANCEL;

    mgr.notify(NOTIFY_ME_ID, note);
  }
 public static Notification buildOngoing(
     Context context, String tickerText, String title, String description) {
   Notification calling =
       new Notification(R.drawable.contacticon, tickerText, System.currentTimeMillis());
   Intent intent = new Intent(context, com.bchalk.GVCallback.callback.CancelCallback.class);
   intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   PendingIntent settings =
       PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
   calling.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
   calling.setLatestEventInfo(context, title, description, settings);
   calling.vibrate = new long[] {250, 250};
   return calling;
 }
    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;
        }
      }
    }
  /**
   * Handles the data returned by UnreadPmCount
   *
   * @param obj
   * @throws Exception
   */
  public void handleUnreadPMData(JSONObject obj) throws Exception {
    int messageCount = obj.getInt("unreadpmcount");

    if (messageCount > 0) {
      NotificationManager manager;
      Notification note;
      PendingIntent pendingIntent;
      Intent intent;

      // Get the notification manager system service
      manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

      // Create a new notification
      note = new Notification(R.drawable.icon, "New SoFurry PM(s)", System.currentTimeMillis());

      // Create the Intent and wrap it in a PendingIntent
      //            intent = new Intent(this, ListPMActivity.class);
      intent = new Intent(this, SFBrowsePMActivity.class);

      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

      pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

      String message = "You have " + messageCount + " new unread message";
      if (messageCount > 1) message += "s";

      message += ".";
      // Set some settings for the notification
      note.setLatestEventInfo(this, "SoFurry PM", message, pendingIntent);

      note.vibrate = AppConstants.VIBRATE_PM_INCOMING;
      note.ledARGB = 0x0000FFFF; // Cyan
      note.ledOffMS = 1500;
      note.ledOnMS = 500;
      note.number = messageCount;
      note.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;

      // Fire off the notification
      manager.notify(AppConstants.NOTIFICATION_ID_PM, note);
    }

    // Set timestamp of when we last checked, for incremental message checks
    PmNotificationService.lastCheck_ = (System.currentTimeMillis() / 1000);
    prefs
        .edit()
        .putLong(AppConstants.PREFERENCE_LAST_PM_CHECK_TIME, PmNotificationService.lastCheck_)
        .commit();
  }
Example #10
0
  @SuppressWarnings("deprecation")
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int notifID;
    NotificationManager nm;
    // Get the notification ID
    notifID = getIntent().getExtras().getInt("NotifID");

    // Create the pending intent that will reference the intent to go when clicked
    Intent i = new Intent(this, MainActivity.class);
    i.putExtra("NotifID", notifID);
    PendingIntent detailsIntent = PendingIntent.getActivity(this, 0, i, 0);

    // Setup notification
    nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Notification notif =
        new Notification(R.drawable.ic_launcher, "Food has expired!", System.currentTimeMillis());

    // Hides status bar notification when clicked
    notif.flags |= Notification.FLAG_AUTO_CANCEL;

    CharSequence from = "RemindMe";
    CharSequence message = "Food has expired!";
    notif.setLatestEventInfo(this, from, message, detailsIntent);

    // ---100ms delay, vibrate for 250ms, pause for 100 ms and
    // then vibrate for 500ms---
    notif.vibrate = new long[] {100, 250, 100, 500};
    nm.notify(notifID, notif);

    // Added sound to notification
    try {
      Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
      Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
      // this.setVolumeControlStream(AudioManager.STREAM_NOTIFICATION);
      r.setStreamType(AudioManager.STREAM_NOTIFICATION);
      r.play();
    } catch (Exception e) {
    }

    // Destroy activity
    finish();
  }
  private void showError(String tickerText, String title, String description) {
    Notification callFailed =
        new Notification(R.drawable.statusicon_error, tickerText, System.currentTimeMillis());
    Intent intent = new Intent(myContext, CancelCallback.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent settings =
        PendingIntent.getActivity(myContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    callFailed.flags = Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL;
    callFailed.ledARGB = 0xFFFF0000;
    callFailed.ledOffMS = 100;
    callFailed.ledOnMS = 100;
    callFailed.vibrate = new long[] {250, 250, 250, 250, 250, 250};
    callFailed.setLatestEventInfo(myContext, title, description, settings);

    NotificationManager mgr =
        (NotificationManager) myContext.getSystemService(Activity.NOTIFICATION_SERVICE);
    if (mgr != null) {
      mgr.notify(GVCallback.Notification.CALL.hashCode(), callFailed);
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // fonctionne sur le principe des Intent Service

    // TODO : builder
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    Notification notif =
        new Notification(R.drawable.ic_launcher, "Message", System.currentTimeMillis());

    notif.vibrate = new long[] {1000, 2000, 1000};

    PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
    // notif.flags |= Notification.FLAG_NO_CLEAR;
    notif.setLatestEventInfo(getApplicationContext(), "titre", "texte", pi);
    nm.notify(200, notif);
  }
Example #13
0
  @SuppressWarnings("deprecation")
  public static void notificate(Activity activity, String title, String message) {

    int count = 0;
    NotificationManager mgr =
        (NotificationManager) activity.getSystemService(Activity.NOTIFICATION_SERVICE);
    int NOTIFY_ME_ID = 1987;

    Notification note =
        new Notification(
            R.drawable.train_icon, "TrainCompany message!", System.currentTimeMillis());

    Intent messageIntent = new Intent(activity, NotificationMessage.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(activity, 0, messageIntent, 0);

    note.setLatestEventInfo(activity, title, message, pendingIntent);
    note.number = ++count;
    note.vibrate = new long[] {500L, 200L, 200L, 500L};
    note.flags |= Notification.FLAG_AUTO_CANCEL;
    mgr.notify(NOTIFY_ME_ID, note);
  }
Example #14
0
  private void initSoundVibrateLights(Notification notification) {
    final String ringtone = settings.getString("settings_key_notif_ringtone", null);
    AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
    if (audioManager.getStreamVolume(AudioManager.STREAM_RING) == 0) {
      notification.sound = null;
    } else if (ringtone != null) notification.sound = Uri.parse(ringtone);
    else notification.defaults |= Notification.DEFAULT_SOUND;

    if (settings.getBoolean("settings_key_notif_icon", true)) {
      notification.icon = R.drawable.ic_stat;
    } else {
      notification.icon = R.drawable.ic_stat_trans;
    }

    if (settings.getBoolean("settings_key_notif_vibrate", false)) {
      long[] vibrate = {0, 1000, 500, 1000, 500, 1000};
      notification.vibrate = vibrate;
    }

    notification.defaults |= Notification.DEFAULT_LIGHTS;
  }
    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 #16
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);
  }
Example #17
0
  @Override
  public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);

    Bundle bundle = intent.getExtras();

    TodoListManager.getInstance().load(bundle.getLong("ListId"));
    task = TaskManager.getInstance().load(bundle.getLong("TaskId"));

    if (task.getReminder() != null) {

      Intent nIntent = new Intent(this, TaskActivity.class);
      nIntent.putExtras(bundle);

      PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, nIntent, 0);

      NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
      Notification notif =
          new Notification(R.drawable.ic_launcher, "WhatsToDo", System.currentTimeMillis());
      notif.setLatestEventInfo(this, "WhatsToDo", "Erinnerung: " + task.getName(), pendingIntent);
      notif.vibrate = new long[] {100, 250, 100, 500};
      nm.notify((int) task.getId(), notif);
    }
  }
  @TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "writeToParcel",
        args = {android.os.Parcel.class, int.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "Notification",
        args = {android.os.Parcel.class})
  })
  public void testWriteToParcel() {
    mNotification = new Notification();
    mNotification.icon = 0;
    mNotification.number = 1;
    final Intent intent = new Intent();
    final PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
    mNotification.contentIntent = pendingIntent;
    final Intent deleteIntent = new Intent();
    final PendingIntent delPendingIntent = PendingIntent.getBroadcast(mContext, 0, deleteIntent, 0);
    mNotification.deleteIntent = delPendingIntent;
    mNotification.tickerText = TICKER_TEXT;

    final RemoteViews contentView =
        new RemoteViews(
            mContext.getPackageName(),
            com.android.internal.R.layout.status_bar_latest_event_content);
    mNotification.contentView = contentView;
    mNotification.defaults = 0;
    mNotification.flags = 0;
    final Uri uri = Uri.parse(URI_STRING);
    mNotification.sound = uri;
    mNotification.audioStreamType = 0;
    final long[] longArray = {1l, 2l, 3l};
    mNotification.vibrate = longArray;
    mNotification.ledARGB = 0;
    mNotification.ledOnMS = 0;
    mNotification.ledOffMS = 0;
    mNotification.iconLevel = 0;
    Parcel parcel = Parcel.obtain();
    mNotification.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    // Test Notification(Parcel)
    Notification result = new Notification(parcel);
    assertEquals(mNotification.icon, result.icon);
    assertEquals(mNotification.when, result.when);
    assertEquals(mNotification.number, result.number);
    assertNotNull(result.contentIntent);
    assertNotNull(result.deleteIntent);
    assertEquals(mNotification.tickerText, result.tickerText);
    assertNotNull(result.contentView);
    assertEquals(mNotification.defaults, result.defaults);
    assertEquals(mNotification.flags, result.flags);
    assertNotNull(result.sound);
    assertEquals(mNotification.audioStreamType, result.audioStreamType);
    assertEquals(mNotification.vibrate[0], result.vibrate[0]);
    assertEquals(mNotification.vibrate[1], result.vibrate[1]);
    assertEquals(mNotification.vibrate[2], result.vibrate[2]);
    assertEquals(mNotification.ledARGB, result.ledARGB);
    assertEquals(mNotification.ledOnMS, result.ledOnMS);
    assertEquals(mNotification.ledOffMS, result.ledOffMS);
    assertEquals(mNotification.iconLevel, result.iconLevel);

    mNotification.contentIntent = null;
    parcel = Parcel.obtain();
    mNotification.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    result = new Notification(parcel);
    assertNull(result.contentIntent);

    mNotification.deleteIntent = null;
    parcel = Parcel.obtain();
    mNotification.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    result = new Notification(parcel);
    assertNull(result.deleteIntent);

    mNotification.tickerText = null;
    parcel = Parcel.obtain();
    mNotification.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    result = new Notification(parcel);
    assertNull(result.tickerText);

    mNotification.contentView = null;
    parcel = Parcel.obtain();
    mNotification.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    result = new Notification(parcel);
    assertNull(result.contentView);

    mNotification.sound = null;
    parcel = Parcel.obtain();
    mNotification.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    result = new Notification(parcel);
    assertNull(result.sound);
  }
Example #19
0
  /**
   * Shows an Astrid notification. Pulls in ring tone and quiet hour settings from preferences. You
   * can make it say anything you like.
   *
   * @param ringTimes number of times to ring (-1 = nonstop)
   */
  public static void showNotification(
      int notificationId, Intent intent, int type, String title, String text, int ringTimes) {
    Context context = ContextManager.getContext();
    if (notificationManager == null) notificationManager = new AndroidNotificationManager(context);

    // quiet hours? unless alarm clock
    boolean quietHours = false;
    int quietHoursStart = Preferences.getIntegerFromString(R.string.p_rmd_quietStart, -1);
    int quietHoursEnd = Preferences.getIntegerFromString(R.string.p_rmd_quietEnd, -1);
    if (quietHoursStart != -1 && quietHoursEnd != -1 && ringTimes >= 0) {
      int hour = new Date().getHours();
      if (quietHoursStart <= quietHoursEnd) {
        if (hour >= quietHoursStart && hour < quietHoursEnd) quietHours = true;
      } else { // wrap across 24/hour boundary
        if (hour >= quietHoursStart || hour < quietHoursEnd) quietHours = true;
      }
    }

    PendingIntent pendingIntent =
        PendingIntent.getActivity(
            context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // set up properties (name and icon) for the notification
    int icon;
    switch (Preferences.getIntegerFromString(R.string.p_rmd_icon, ICON_SET_ASTRID)) {
      case ICON_SET_PINK:
        icon = R.drawable.notif_pink_alarm;
        break;
      case ICON_SET_BORING:
        icon = R.drawable.notif_boring_alarm;
        break;
      default:
        icon = R.drawable.notif_astrid;
    }

    // create notification object
    Notification notification = new Notification(icon, text, System.currentTimeMillis());
    notification.setLatestEventInfo(context, title, text, pendingIntent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    if (Preferences.getBoolean(R.string.p_rmd_persistent, true)) {
      notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_SHOW_LIGHTS;
      notification.ledOffMS = 5000;
      notification.ledOnMS = 700;
      notification.ledARGB = Color.YELLOW;
    } else notification.defaults = Notification.DEFAULT_LIGHTS;

    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

    // detect call state
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    int callState = tm.getCallState();

    boolean voiceReminder = Preferences.getBoolean(R.string.p_voiceRemindersEnabled, false);

    // if multi-ring is activated, set up the flags for insistent
    // notification, and increase the volume to full volume, so the user
    // will actually pay attention to the alarm
    if (ringTimes != 1 && (type != ReminderService.TYPE_RANDOM)) {
      notification.audioStreamType = AudioManager.STREAM_ALARM;
      audioManager.setStreamVolume(
          AudioManager.STREAM_ALARM, audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM), 0);

      // insistent rings until notification is disabled
      if (ringTimes < 0) {
        notification.flags |= Notification.FLAG_INSISTENT;
        voiceReminder = false;
      }

    } else {
      notification.audioStreamType = AudioManager.STREAM_NOTIFICATION;
    }

    // quiet hours = no sound
    if (quietHours || callState != TelephonyManager.CALL_STATE_IDLE) {
      notification.sound = null;
      voiceReminder = false;
    } else {
      String notificationPreference = Preferences.getStringValue(R.string.p_rmd_ringtone);
      if (audioManager.getStreamVolume(AudioManager.STREAM_RING) == 0) {
        notification.sound = null;
        voiceReminder = false;
      } else if (notificationPreference != null) {
        if (notificationPreference.length() > 0) {
          Uri notificationSound = Uri.parse(notificationPreference);
          notification.sound = notificationSound;
        } else {
          notification.sound = null;
        }
      } else {
        notification.defaults |= Notification.DEFAULT_SOUND;
      }
    }

    // quiet hours && ! due date or snooze = no vibrate
    if (quietHours && !(type == ReminderService.TYPE_DUE || type == ReminderService.TYPE_SNOOZE)) {
      notification.vibrate = null;
    } else if (callState != TelephonyManager.CALL_STATE_IDLE) {
      notification.vibrate = null;
    } else {
      if (Preferences.getBoolean(R.string.p_rmd_vibrate, true)
          && audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_NOTIFICATION)) {
        notification.vibrate = new long[] {0, 1000, 500, 1000, 500, 1000};
      } else {
        notification.vibrate = null;
      }
    }

    if (Constants.DEBUG)
      Log.w("Astrid", "Logging notification: " + text); // $NON-NLS-1$ //$NON-NLS-2$

    for (int i = 0; i < Math.max(ringTimes, 1); i++) {
      notificationManager.notify(notificationId, notification);
      AndroidUtilities.sleepDeep(500);
    }

    if (voiceReminder) {
      AndroidUtilities.sleepDeep(2000);
      for (int i = 0; i < 50; i++) {
        AndroidUtilities.sleepDeep(500);
        if (audioManager.getMode() != AudioManager.MODE_RINGTONE) break;
      }
      try {
        VoiceOutputService.getVoiceOutputInstance().queueSpeak(text);
      } catch (VerifyError e) {
        // unavailable
      }
    }
  }
Example #20
0
  private void showNotification(int moodId, String text) {
    Log.d("Kupluk", "start showNotification()");
    Notification notification = new Notification(moodId, null, System.currentTimeMillis());
    // boolean useSound = true;
    // boolean useVibrate = false;
    // boolean useLed = false;

    mode = Pengaturan.getMode(this);
    char b = mode.charAt(0);
    Log.d("kupluk", "mode: " + b);
    switch (b) {
      case '0':
        {
          // notification.sound=
          // Uri.parse("file:///sdcard/notification/adzan.mp3");

          notification.sound = Uri.parse("android.resource://com.amiral.kupluk/" + R.raw.adzan);
          Log.d("Kupluk", "Suara diterima");
        }
        break;
      case '1':
        {
          notification.vibrate = new long[] {1000, 1000, 1000, 1000, 1000};
          // notification.defaults |= Notification.DEFAULT_VIBRATE;
          Log.d("Kupluk", "Getar diterima");
        }
        ;
        break;
      case '2':
        {
          // notification.ledARGB = 0xff00ff00;
          notification.ledARGB = Color.BLUE;
          notification.ledOnMS = 1500;
          notification.ledOffMS = 800;
          notification.flags |= Notification.FLAG_SHOW_LIGHTS;
          Log.d("Kupluk", "Lampu Diterima");
        }
        break;
    }

    /*
     * if (useSound) {
     *
     * } if (useVibrate) { notification.vibrate = new long[] {50, 250, 200,
     * 1200}; Log.d("Kupluk", "trigger vibrate notification"); } if (useLed)
     * { notification.ledARGB = 0xff00ff00; notification.ledOnMS = 1500;
     * notification.ledOffMS = 800; notification.flags |=
     * Notification.FLAG_SHOW_LIGHTS ; Log.d("Kupluk",
     * "trigger led notification"); }
     */

    // The PendingIntent to launch our activity if the user selects this
    // notification
    PendingIntent contentIntent =
        PendingIntent.getActivity(this, 0, new Intent(this, KuplukMain.class), 0);

    // Set the info for the views that show in the notification panel.
    notification.setLatestEventInfo(this, "Kupluk - Remainder", text, contentIntent);

    // Send the notification.
    mNM.notify(NOTIF_ID, notification);
    Log.d("Kupluk", "end showNotification()");
  }
  // 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();
      }
    }
  }
 public mUseChronometer setVibrate(long al[])
 {
     mNotification.vibrate = al;
     return this;
 }