Ejemplo n.º 1
1
  private void noticeNewBlog(Context context) {
    NotificationManager notiManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notiManager.cancel(Constants.NOTIFICATION_NEW_MICRO_BLOG); // 先清除上一次提醒;

    Intent intent = new Intent();
    // 粉丝
    if (entity.getContentType() == Skeleton.TYPE_MORE) {
      intent.setAction("com.shejiaomao.weibo.SOCIAL_GRAPH");
      intent.addCategory("android.intent.category.DEFAULT");
      intent.putExtra("SOCIAL_GRAPH_TYPE", SocialGraphTask.TYPE_FOLLOWERS);
      intent.putExtra("USER", account.getUser());
    } else {
      intent.setAction("com.shejiaomao.weibo.MAIN");
      intent.addCategory("android.intent.category.DEFAULT");
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    }
    intent.putExtra("CONTENT_TYPE", entity.getContentType());
    intent.putExtra("ACCOUNT", account);

    Notification notification = new Notification();
    notification.icon = R.drawable.icon_notification;
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    notification.tickerText = entity.getTickerText();

    if (sheJiaoMao.isVibrateNotification()) {
      notification.defaults |= Notification.DEFAULT_VIBRATE;
    }
    if (sheJiaoMao.isRingtoneNotification()) {
      if (StringUtil.isNotEmpty(sheJiaoMao.getRingtoneUri())) {
        notification.sound = Uri.parse(sheJiaoMao.getRingtoneUri());
      } else {
        notification.defaults |= Notification.DEFAULT_SOUND;
      }
    }

    if (sheJiaoMao.isFlashingLEDNotification()) {
      notification.ledARGB = Color.GREEN;
      notification.ledOffMS = 1000;
      notification.ledOnMS = 1000;
      notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    }

    int requestCode = account.getAccountId().intValue() * 100 + entity.getContentType();
    PendingIntent pendingIntent =
        PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    notification.setLatestEventInfo(
        context, entity.getContentTitle(), entity.getContentText(), pendingIntent);

    notiManager.notify(requestCode, notification);
  }
  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);
  }
  public void onReceive(Context context, Intent intent) {

    int icon = android.R.drawable.alert_dark_frame;
    Notification notification = new Notification(icon, "things to do", System.currentTimeMillis());

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);

    boolean ringtoneActive = preferences.getBoolean("ringtone_active", false);
    String ringtone =
        preferences.getString("ringtone_selected", Settings.System.DEFAULT_RINGTONE_URI.toString());

    boolean ledActive = preferences.getBoolean("led_active", false);

    boolean vibrateActive = preferences.getBoolean("vibrate_active", false);

    Log.d("QuickReminder", "Ringtone is " + (ringtoneActive ? "active" : "not active"));

    if (ringtoneActive) {
      Log.d("QuickReminder", "Selected Ringtone: " + ringtone);
      notification.sound = Uri.parse(ringtone);
    }

    if (ledActive) {
      notification.ledOnMS = 1000;
      notification.ledOffMS = 1000;
      notification.ledARGB = Color.argb(0, 0, 100, 100);
      notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    }

    if (vibrateActive) {
      notification.defaults |= Notification.DEFAULT_VIBRATE;
    }

    CharSequence contentTitle = "QuickReminder";

    CharSequence contentText = intent.getExtras().getString("taskname");
    long taskNotificationId = intent.getExtras().getLong("taskid");

    Log.d("QuickReminder", "Creating notification with id " + (int) taskNotificationId);

    Intent notificationIntent = new Intent(context, QuickReminderActivity.class);
    notificationIntent.putExtra("tasknotificationid", taskNotificationId);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    notificationIntent.setData(Uri.parse("quickReminder://" + taskNotificationId));

    PendingIntent contentIntent =
        PendingIntent.getActivity(
            context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

    NotificationManager notificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify((int) taskNotificationId, notification);
  }
Ejemplo n.º 4
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 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 static void playPushNotificationSound(
      Context context, Notification notification, String sound) {
    if (sound != null && sound.length() != 0) {
      int soundId = context.getResources().getIdentifier(sound, "raw", context.getPackageName());
      if (0 != soundId) {
        // if found valid resource id
        notification.sound =
            Uri.parse("android.resource://" + context.getPackageName() + "/" + soundId);
        return;
      }
    }

    // try to get default one
    notification.defaults |= Notification.DEFAULT_SOUND;
  }
  private void setRinger(long providerId, Notification notification) {
    Imps.ProviderSettings.QueryMap settings = getProviderSettings(providerId);
    String ringtoneUri = settings.getRingtoneURI();
    boolean vibrate = settings.getVibrate();

    notification.sound = TextUtils.isEmpty(ringtoneUri) ? null : Uri.parse(ringtoneUri);
    if (notification.sound != null) {
      mLastSoundPlayedMs = SystemClock.elapsedRealtime();
    }

    if (DBG) log("setRinger: notification.sound = " + notification.sound);

    if (vibrate) {
      notification.defaults |= Notification.DEFAULT_VIBRATE;
      if (DBG) log("setRinger: defaults |= vibrate");
    }
  }
    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);
      }
    }
Ejemplo n.º 9
0
  /**
   * @param context
   * @param title
   * @param content
   * @param sound
   * @param intent
   */
  public static void showNotification(
      Context context, String title, String content, String sound, Intent intent) {
    intent.setFlags(0);
    int notificationId = (new Random()).nextInt();
    PendingIntent contentIntent = PendingIntent.getBroadcast(context, notificationId, intent, 0);
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.login_head_icon)
            .setContentTitle(title)
            .setAutoCancel(true)
            .setContentIntent(contentIntent)
            .setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND)
            .setContentText(content);

    // NotificationManager 是一个系统Service,必须通过 getSystemService()方法来获取
    NotificationManager manager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = mBuilder.build();
    if (sound != null && sound.trim().length() > 0) {
      notification.sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + sound);
    }
    manager.notify(notificationId, notification);
  }
Ejemplo n.º 10
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
      }
    }
  }
  @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);
  }
 public mSortKey setSound(Uri uri)
 {
     mNotification.sound = uri;
     mNotification.audioStreamType = -1;
     return this;
 }
Ejemplo n.º 13
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()");
  }
Ejemplo n.º 14
0
  private static void notifyFailed(
      Context context, boolean isDownload, long threadId, boolean noisy) {
    // TODO factor out common code for creating notifications
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);

    boolean enabled = sp.getBoolean(MessagingPreferenceActivity.NOTIFICATION_ENABLED, true);
    if (!enabled) {
      return;
    }

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

    // Strategy:
    // a. If there is a single failure notification, tapping on the notification goes
    //    to the compose view.
    // b. If there are two failure it stays in the thread view. Selecting one undelivered
    //    thread will dismiss one undelivered notification but will still display the
    //    notification.If you select the 2nd undelivered one it will dismiss the notification.

    long[] msgThreadId = {0, 1}; // Dummy initial values, just to initialize the memory
    int totalFailedCount = getUndeliveredMessageCount(context, msgThreadId);
    if (totalFailedCount == 0 && !isDownload) {
      return;
    }
    // The getUndeliveredMessageCount method puts a non-zero value in msgThreadId[1] if all
    // failures are from the same thread.
    // If isDownload is true, we're dealing with 1 specific failure; therefore "all failed" are
    // indeed in the same thread since there's only 1.
    boolean allFailedInSameThread = (msgThreadId[1] != 0) || isDownload;

    Intent failedIntent;
    Notification notification = new Notification();
    String title;
    String description;
    if (totalFailedCount > 1) {
      description =
          context.getString(
              R.string.notification_failed_multiple, Integer.toString(totalFailedCount));
      title = context.getString(R.string.notification_failed_multiple_title);
    } else {
      title =
          isDownload
              ? context.getString(R.string.message_download_failed_title)
              : context.getString(R.string.message_send_failed_title);

      description = context.getString(R.string.message_failed_body);
    }

    if (allFailedInSameThread) {
      failedIntent = new Intent(context, ComposeMessageActivity.class);
      if (isDownload) {
        // When isDownload is true, the valid threadId is passed into this function.
        failedIntent.putExtra("failed_download_flag", true);
      } else {
        threadId = msgThreadId[0];
        failedIntent.putExtra("undelivered_flag", true);
      }
      failedIntent.putExtra("thread_id", threadId);
    } else {
      failedIntent = new Intent(context, ConversationList.class);
    }

    failedIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent =
        PendingIntent.getActivity(context, 0, failedIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    notification.icon = R.drawable.stat_notify_sms_failed;

    notification.tickerText = title;

    notification.setLatestEventInfo(context, title, description, pendingIntent);

    if (noisy) {
      boolean vibrate =
          sp.getBoolean(
              MessagingPreferenceActivity.NOTIFICATION_VIBRATE,
              false /* don't vibrate by default */);
      if (vibrate) {
        notification.defaults |= Notification.DEFAULT_VIBRATE;
      }

      String ringtoneStr = sp.getString(MessagingPreferenceActivity.NOTIFICATION_RINGTONE, null);
      notification.sound = TextUtils.isEmpty(ringtoneStr) ? null : Uri.parse(ringtoneStr);
    }

    if (isDownload) {
      nm.notify(DOWNLOAD_FAILED_NOTIFICATION_ID, notification);
    } else {
      nm.notify(MESSAGE_FAILED_NOTIFICATION_ID, notification);
    }
  }
Ejemplo n.º 15
0
  private static void updateNotification(
      Context context,
      Intent clickIntent,
      String description,
      int iconRes,
      boolean isNew,
      CharSequence ticker,
      long timeMillis,
      String title,
      int messageCount,
      int uniqueThreadCount) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);

    if (!sp.getBoolean(MessagingPreferenceActivity.NOTIFICATION_ENABLED, true)) {
      return;
    }

    Notification notification = new Notification(iconRes, ticker, timeMillis);

    // If we have more than one unique thread, change the title (which would
    // normally be the contact who sent the message) to a generic one that
    // makes sense for multiple senders, and change the Intent to take the
    // user to the conversation list instead of the specific thread.
    if (uniqueThreadCount > 1) {
      title = context.getString(R.string.notification_multiple_title);
      clickIntent = new Intent(Intent.ACTION_MAIN);

      clickIntent.setFlags(
          Intent.FLAG_ACTIVITY_NEW_TASK
              | Intent.FLAG_ACTIVITY_SINGLE_TOP
              | Intent.FLAG_ACTIVITY_CLEAR_TOP);

      clickIntent.setType("vnd.android-dir/mms-sms");
    }

    // If there is more than one message, change the description (which
    // would normally be a snippet of the individual message text) to
    // a string indicating how many "unseen" messages there are.
    if (messageCount > 1) {
      description =
          context.getString(R.string.notification_multiple, Integer.toString(messageCount));
    }

    // Make a startActivity() PendingIntent for the notification.
    PendingIntent pendingIntent =
        PendingIntent.getActivity(context, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    // Update the notification.
    notification.setLatestEventInfo(context, title, description, pendingIntent);

    if (isNew) {
      String vibrateWhen;
      if (sp.contains(MessagingPreferenceActivity.NOTIFICATION_VIBRATE_WHEN)) {
        vibrateWhen = sp.getString(MessagingPreferenceActivity.NOTIFICATION_VIBRATE_WHEN, null);
      } else if (sp.contains(MessagingPreferenceActivity.NOTIFICATION_VIBRATE)) {
        vibrateWhen =
            sp.getBoolean(MessagingPreferenceActivity.NOTIFICATION_VIBRATE, false)
                ? context.getString(R.string.prefDefault_vibrate_true)
                : context.getString(R.string.prefDefault_vibrate_false);
      } else {
        vibrateWhen = context.getString(R.string.prefDefault_vibrateWhen);
      }

      boolean vibrateAlways = vibrateWhen.equals("always");
      boolean vibrateSilent = vibrateWhen.equals("silent");
      AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
      boolean nowSilent = audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE;

      if (vibrateAlways || vibrateSilent && nowSilent) {
        notification.defaults |= Notification.DEFAULT_VIBRATE;
      }

      String ringtoneStr = sp.getString(MessagingPreferenceActivity.NOTIFICATION_RINGTONE, null);
      notification.sound = TextUtils.isEmpty(ringtoneStr) ? null : Uri.parse(ringtoneStr);
    }

    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.defaults |= Notification.DEFAULT_LIGHTS;

    // set up delete intent
    notification.deleteIntent =
        PendingIntent.getBroadcast(context, 0, sNotificationOnDeleteIntent, 0);

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

    nm.notify(NOTIFICATION_ID, notification);
  }
 public mNotification setSound(Uri uri, int i)
 {
     mNotification.sound = uri;
     mNotification.audioStreamType = i;
     return this;
 }
Ejemplo n.º 17
0
  /** Issues a notification to inform the user that server has sent a message. */
  @SuppressWarnings("deprecation")
  private void generateNotification(Context context, String message, String type, String pieQty) {
    log.e(TAG, "GMCmessage " + message);
    String _message = message.toLowerCase();
    if (_message.contains(context.getString(R.string.message_contain_checkin1))
        || _message.contains(context.getString(R.string.message_contain_checkin2))
        || _message.contains(context.getString(R.string.message_contain_checkin3))) {
      mShoppieSharePref.setCheckinStatus(1);
      openPieAnimate(Integer.parseInt(pieQty));
    } else mShoppieSharePref.setCheckinStatus(0);
    int icon = R.drawable.icon_launcher;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);

    String title = context.getString(R.string.app_name);

    Intent notificationIntent = new Intent(context, ActivityLogo.class);
    notificationIntent.putExtra(ActivityNotification.FLAG_NOTIFI, type);
    notificationIntent.putExtra(ActivityNotification.FLAG_NOTIFI_DATA, pieQty);
    // set intent so it does not start a new activity
    notificationIntent.setFlags(
        /* Intent.FLAG_ACTIVITY_CLEAR_TOP | */ Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    // Play default notification sound
    notification.defaults |= Notification.DEFAULT_SOUND;

    notification.sound =
        Uri.parse("android.resource://vn.com.shoppie" /*
																			 * +
																			 * context
																			 * .
																			 * getPackageName
																			 * (
																			 * )
																			 */ + "/" + R.raw.ting_ting);

    // Vibrate if vibrate is enabled
    notification.defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE;
    int notiId = 0;
    if (type.equals(GlobalValue.EXTRA_TYPE_CHECKIN)) notiId = GlobalValue.NOTIFICATION_ID_CHECKIN;
    if (type.equals(GlobalValue.EXTRA_TYPE_REGISTER)) notiId = GlobalValue.NOTIFICATION_ID_REGISTER;
    if (type.equals(GlobalValue.EXTRA_TYPE_PURCHASE))
      notiId = GlobalValue.NOTIFICATION_ID_PURCHARSE;
    notificationManager.notify(notiId, notification);

    try {
      GcmNotifyMng gcmNotifyMng = new GcmNotifyMng(context);
      GcmNotify notify = new GcmNotify(-1, new String[GcmNotify.NUM_FIELDS]);
      notify.message = message;
      notify.type = type;
      notify.pieQty = pieQty + "";
      notify.time = System.currentTimeMillis() + "";
      gcmNotifyMng.insertNewTo(notify.getValues());
    } catch (SQLException e) {
      log.e("SQL exception", "can not insert New gcm notify to db");
    }
  }