Ejemplo n.º 1
1
  @Override
  protected void onDestroy() {
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    int icon = R.drawable.icon;
    CharSequence tickerText =
        getResources().getString(R.string.ministro_repository_changed_msg); // ticker-text
    long when = System.currentTimeMillis(); // notification time
    Context context = getApplicationContext(); // application Context
    CharSequence contentTitle =
        getResources().getString(R.string.ministro_update_msg); // expanded message title
    CharSequence contentText =
        getResources()
            .getString(R.string.ministro_repository_changed_tap_msg); // expanded message text

    Intent notificationIntent = new Intent(this, MinistroActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    // the next two lines initialize the Notification, using the configurations above
    Notification notification = new Notification(icon, tickerText, when);
    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    notification.defaults |= Notification.DEFAULT_LIGHTS;
    try {
      nm.notify(1, notification);
    } catch (Exception e) {
      e.printStackTrace();
    }
    super.onDestroy();
  }
 private static void startNotification() {
   Intent i = new Intent(context, SalatTimes.class);
   notification.setLatestEventInfo(
       context,
       context.getString(R.string.app_name),
       notification.tickerText,
       PendingIntent.getActivity(
           context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT));
   notification.contentIntent =
       PendingIntent.getBroadcast(
           context,
           0,
           new Intent(context, ClickNotificationReceiver.class),
           PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
   notification.deleteIntent =
       PendingIntent.getBroadcast(
           context,
           0,
           new Intent(context, ClearNotificationReceiver.class),
           PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
   ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE))
       .notify(1, notification);
   if (mediaPlayer == null || !mediaPlayer.isPlaying()) {
     try {
       Thread.sleep(CONSTANT.POST_NOTIFICATION_DELAY);
     } catch (Exception ex) {
       // Just trying to make sure the notification completes before we fall asleep again
     }
     WakeLock.release();
   }
 }
Ejemplo n.º 3
0
  /** Issues a notification to inform the user that server has sent a message. */
  private static void generateNotification(Context context, String message) {
    int icon = R.drawable.ic_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, MainActivity.class);
    // 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://" + context.getPackageName() +
    // "your_sound_file_name.mp3");

    // Vibrate if vibrate is enabled
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    notificationManager.notify(0, notification);
  }
Ejemplo n.º 4
0
  /** Issues a notification to inform the user that server has sent a message. */
  private static void generateNotification(Context context, String title, String message) {
    int icon = R.drawable.ic_stat_gcm;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    if ((title == null) || (title.equals(""))) {
      title = context.getString(R.string.app_name);
    }
    Intent notificationIntent = new Intent(context, DemoActivity.class);
    // 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 notification =
        new NotificationCompat.Builder(context)
            .setContentTitle(title)
            .setContentText(message)
            .setContentIntent(intent)
            .setSmallIcon(icon)
            .setWhen(when)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
            .build();

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);
  }
  /**
   * generate chat notification
   *
   * @param context
   * @param message
   * @param userId
   */
  @SuppressWarnings("deprecation")
  public void generateNotification(
      Context context, String message, String fullname, String userImage, String userId) {
    int icon = R.drawable.ic_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 = null;

    notificationIntent = new Intent(context, ChatActivity.class);
    notificationIntent.putExtra("fullname", fullname);
    notificationIntent.putExtra("user_id", userId);
    notificationIntent.putExtra("image", userImage);

    PendingIntent intent =
        PendingIntent.getActivity(
            context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setLatestEventInfo(context, title, message, intent);

    notification.flags |= Notification.FLAG_AUTO_CANCEL;

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

    // Vibrate if vibrate is enabled
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    notificationManager.notify(0, notification);
  }
 @Override
 public void onStop(DownloadTask task) throws RemoteException {
   if (mNotificationManager != null && mNotification != null) {
     mNotification.tickerText = mStopTickerText;
     mNotification.flags = Notification.FLAG_AUTO_CANCEL;
     mNotification.contentIntent = mPendingIntent;
     //			if (RecommAppsUtils.isZh()) {
     mNotification.setLatestEventInfo(
         mContext,
         mPauseText,
         mProgressText + " " + task.getAlreadyDownloadPercent() + "%",
         mPendingIntent);
     //			} else {
     //				mNotification.setLatestEventInfo(mContext, mPauseText,
     //						task.getAlreadyDownloadPercent() + "%",
     //						mPendingIntent);
     //			}
     //			mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification);
     if (mNotification.contentView != null) {
       mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification);
     }
   }
   if (task != null) {
     // add by xiedezhi
     sendBroadcastingToAppCenter(task);
   }
 }
    //	通知センターに通知を残す(pecoriできる人がいます)
    private void notifyNearUser(HttpResponse res) throws Exception {
      String body = EntityUtils.toString(res.getEntity(), "UTF-8");
      JSONObject json = new JSONObject(body.toString());
      JSONArray nearUsers = json.getJSONArray("near_users");
      for (int i = 0; i < nearUsers.length(); i++) {
        JSONObject user = nearUsers.getJSONObject(i);
        String facebookId = user.getString("facebook_id");
        String name = user.getString("name");

        NotificationManager notificationManager =
            (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        Notification notification =
            new Notification(
                android.R.drawable.btn_default,
                "近くに" + name + "さんがいるようです。",
                System.currentTimeMillis());
        notification.flags = Notification.FLAG_AUTO_CANCEL;

        //	Notificationが選択された場合のIntent
        Intent intent = new Intent(Intent.ACTION_VIEW);
        PendingIntent contentIntent =
            PendingIntent.getActivity(LocationDetectService.this, 0, intent, 0);
        notification.setLatestEventInfo(
            getApplicationContext(), "Pecori", "近くに" + name + "さんがいるようです。", contentIntent);
        notificationManager.notify(R.string.app_name, notification);
      }
    }
  private void createNotification(String title, String description, int tag) {
    NotificationManager notificationManager =
        (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Intent intent = new Intent(this, NotificationActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("tag", counter);
    PendingIntent pIntent =
        PendingIntent.getActivity(this, counter, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // Build notification
    // Actions are just fake
    NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(this)
            .setContentTitle(title)
            .setContentText(description)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentIntent(pIntent);
    notificationBuilder.setContentIntent(pIntent);
    Notification notification = notificationBuilder.build();
    // Hide the notification after its selected
    // noti.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.flags |= Notification.DEFAULT_VIBRATE;
    notification.flags |= Notification.DEFAULT_SOUND;
    notification.flags |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(tag, notification);
  }
  public void tampilkanNotifikasiPeringatan(Peringatan peringatan) {

    int icon = R.drawable.pelanggaran;
    CharSequence tickerText = "";
    CharSequence contentTitle = "";
    long when = System.currentTimeMillis();

    DatabaseManagerOrtu databaseManager = new DatabaseManagerOrtu(context);
    DataMonitoring dataMonitoring =
        databaseManager.getDataMonitoringByIdMonitoring(peringatan.getIdMonitoring(), true, true);

    Anak anak = dataMonitoring.getAnak();

    if (peringatan.getTipe() == TipePesanMonak.PERINGATAN_TERLARANG) {
      tickerText =
          anak.getNamaAnak() + " melakukan pelanggaran..." + "!!!PERINGATAN TERLARANG" + "!!!";
      contentTitle = "PERINGATAN TERLARANG";
    } else {
      tickerText =
          anak.getNamaAnak() + " melakukan pelanggaran..." + "!!!PERINGATAN SEHARUSNYA" + "!!!";
      contentTitle = "PERINGATAN SEHARUSNYA";
    }

    Notification notification = new Notification(icon, tickerText, when);
    CharSequence contentText =
        "anak : " + anak.getNamaAnak() + "\n" + "click disini untuk lihat lokasi";
    Intent notificationIntent = new Intent(context, Peta.class);
    notificationIntent.putExtra(Peta.EXTRA_ACTION, Peta.EXTRA_PELANGGARAN);

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

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

    mNotificationManager.notify(PELANGGARAN_NOTIFIKASI, notification);
  }
Ejemplo n.º 10
0
  /** Creates a notification of the specified type for a contact. */
  public void createNotification(NotificationType type, int notificationId, Contact contact) {
    Notification notification = new Notification(-1, null, System.currentTimeMillis());

    notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;

    RemoteViews contentView = new RemoteViews(_context.getPackageName(), R.layout.notification);

    // set the photo
    contentView.setImageViewBitmap(
        R.id.notification_contact_photo, ContactsHelper.getPhoto(_context, contact));

    // set the verb, i.e. "call" or "text"
    contentView.setTextViewText(
        R.id.notification_notification_type, _context.getString(type.getVerbStringId()));

    // set the name and type
    contentView.setTextViewText(R.id.notification_contact_name, contact.getDisplayName());
    contentView.setTextViewText(R.id.notification_contact_type, contact.getType());

    // set the number
    contentView.setTextViewText(R.id.notification_contact_number, contact.getNumber());

    notification.contentView = contentView;

    // create the intent that will fire when the contact is selected
    Intent intent = new Intent(type.getAction(), Uri.parse(type.getScheme() + contact.getNumber()));
    PendingIntent contentIntent = PendingIntent.getActivity(_context, 0, intent, 0);
    notification.contentIntent = contentIntent;

    _manager.notify(notificationId, notification);
  }
Ejemplo n.º 11
0
  @Override
  void doReminderWork(Intent intent) {
    Log.d("ReminderService", "Doing work.");
    Long rowId = intent.getExtras().getLong(RemindersDbAdapter.KEY_ROWID);

    NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    Intent notificationIntent = new Intent(this, ReminderEditActivity.class);
    notificationIntent.putExtra(RemindersDbAdapter.KEY_ROWID, rowId);

    PendingIntent pi = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    Notification note =
        new Notification(
            android.R.drawable.ic_menu_my_calendar,
            getString(R.string.notify_new_task_message),
            System.currentTimeMillis());
    note.setLatestEventInfo(
        this,
        getString(R.string.notify_new_task_title),
        getString(R.string.notify_new_task_message),
        pi);
    note.defaults |= Notification.DEFAULT_SOUND;
    note.defaults |= Notification.DEFAULT_VIBRATE;
    note.flags |= Notification.FLAG_AUTO_CANCEL;

    // An issue could occur if user ever enters over 2,147,483,647 tasks. (Max int value).
    // I highly doubt this will ever happen. But is good to note.
    int id = (int) ((long) rowId);
    mgr.notify(id, note);
  }
Ejemplo n.º 12
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();
  }
Ejemplo n.º 13
0
  private void createNotification(
      String title, String description, int notificationId, int smallIcon) {
    Log.d(
        TAG, "createNotification() creating notification [notificationId:" + notificationId + "]");
    NotificationManager notificationManager =
        (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // CREATE THE INTENT TO START WHEN THE NOTIFICATION IS CLICKED
    Intent intent = new Intent(this, NotificationActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(NotificationActivity.EXTRA_KEY1, "today is the day (" + notificationId + ")");
    intent.putExtra(NotificationUtil.NOTIFICATION_ID, notificationId);

    // CREATE THE PENDING INTENT
    PendingIntent pIntent =
        PendingIntent.getActivity(this, counter, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // Build notification
    // Actions are just fake
    NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(this)
            .setContentTitle(title)
            .setContentText(description)
            .setSmallIcon(smallIcon)
            .setContentIntent(pIntent);
    Notification notification = notificationBuilder.build();
    // Hide the notification after its selected
    // noti.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.flags |= Notification.DEFAULT_VIBRATE;
    notification.flags |= Notification.DEFAULT_SOUND;
    notification.flags |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(notificationId, notification);
  }
Ejemplo n.º 14
0
  /**
   * Custom View Notification
   *
   * @return Notification
   * @see CreateNotification
   */
  private Notification setCustomViewNotification() {

    // Creates an explicit intent for an ResultActivity to receive.
    Intent resultIntent = new Intent(this, ResultActivity.class);

    // This ensures that the back button follows the recommended convention for the back key.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(ResultActivity.class);

    // Adds the Intent that starts the Activity to the top of the stack.
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    // Create remote view and set bigContentView.
    RemoteViews expandedView =
        new RemoteViews(this.getPackageName(), R.layout.notification_custom_remote);
    expandedView.setTextViewText(R.id.text_view, "Neat logo!");

    Notification notification =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setAutoCancel(true)
            .setContentIntent(resultPendingIntent)
            .setContentTitle("Custom View")
            .build();

    notification.bigContentView = expandedView;

    return notification;
  }
Ejemplo n.º 15
0
  @Override
  protected void onPostExecute(SaveImageInBackgroundData params) {
    if (params.result > 0) {
      // Show a message that we've failed to save the image to disk
      GlobalScreenshot.notifyScreenshotError(params.context, mNotificationManager);
    } else {
      // Show the final notification to indicate screenshot saved
      Resources r = params.context.getResources();

      // Create the intent to show the screenshot in gallery
      Intent launchIntent = new Intent(Intent.ACTION_VIEW);
      launchIntent.setDataAndType(params.imageUri, "image/png");
      launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

      mNotificationBuilder
          .setContentTitle(r.getString(R.string.screenshot_saved_title))
          .setContentText(r.getString(R.string.screenshot_saved_text))
          .setContentIntent(PendingIntent.getActivity(params.context, 0, launchIntent, 0))
          .setWhen(System.currentTimeMillis())
          .setAutoCancel(true);

      Notification n = mNotificationBuilder.getNotification();
      n.flags &= ~Notification.FLAG_NO_CLEAR;
      mNotificationManager.notify(mNotificationId, n);
    }
    params.finisher.run();
  }
Ejemplo n.º 16
0
 @Override
 public void onClick(View v) {
   NotificationManager manager =
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
   PendingIntent pendingIntent2 =
       PendingIntent.getActivity(
           this, 0, new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
   // 通过Notification.Builder来创建通知,注意API Level
   // API11之后才支持
   Notification notify2 =
       new Notification.Builder(this)
           .setSmallIcon(
               R.mipmap
                   .ic_launcher) // 设置状态栏中的小图片,尺寸一般建议在24×24,这个图片同样也是在下拉状态栏中所显示,如果在那里需要更换更大的图片,可以使用setLargeIcon(Bitmap
           // icon)
           .setTicker("TickerText:" + "您有新短消息,请注意查收!") // 设置在status
           // bar上显示的提示文字
           .setContentTitle("Notification Title") // 设置在下拉status
           // bar后Activity,本例子中的NotififyMessage的TextView中显示的标题
           .setContentText("This is the notification message") // TextView中显示的详细内容
           .setContentIntent(pendingIntent2) // 关联PendingIntent
           .setNumber(
               1) // 在TextView的右方显示的数字,可放大图片看,在最右侧。这个number同时也起到一个序列号的左右,如果多个触发多个通知(同一ID),可以指定显示哪一个。
           .getNotification(); // 需要注意build()是在API level
   // 16及之后增加的,在API11中可以使用getNotificatin()来代替
   notify2.flags |= Notification.FLAG_AUTO_CANCEL;
   manager.notify(i++, notify2);
 }
Ejemplo n.º 17
0
  // 在状态栏提示分享操作
  private void showNotification(long cancelTime, String text) {
    try {
      Context app = getContext().getApplicationContext();
      NotificationManager nm =
          (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE);
      final int id = Integer.MAX_VALUE / 13 + 1;
      nm.cancel(id);

      long when = System.currentTimeMillis();
      Notification notification = new Notification(notifyIcon, text, when);
      PendingIntent pi = PendingIntent.getActivity(app, 0, new Intent(), 0);
      notification.setLatestEventInfo(app, notifyTitle, text, pi);
      notification.flags = Notification.FLAG_AUTO_CANCEL;
      nm.notify(id, notification);

      if (cancelTime > 0) {
        Message msg = new Message();
        msg.what = MSG_CANCEL_NOTIFY;
        msg.obj = nm;
        msg.arg1 = id;
        UIHandler.sendMessageDelayed(msg, cancelTime, this);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 18
0
  // Notification
  public void showStartNotification() {
    notification.flags = Notification.FLAG_ONGOING_EVENT;

    notification.setLatestEventInfo(
        this, getString(R.string.app_name), getString(R.string.qaul_running), this.mainIntent);
    this.notificationManager.notify(-1, this.notification);
  }
Ejemplo n.º 19
0
    public void notify(String sender, String message, String tripid, Context context) {
      NotificationCompat.Builder mBuilder =
          new NotificationCompat.Builder(context)
              .setSmallIcon(R.drawable.ic_launcher)
              .setContentTitle(sender)
              .setContentText(message);
      // Creates an explicit intent for an Activity in your app
      Intent resultIntent = new Intent(context, ChatActivity.class);
      resultIntent.putExtra("email", sender);
      resultIntent.putExtra("message", message);
      resultIntent.putExtra("tripid", tripid);

      // The stack builder object will contain an artificial back stack for
      // the
      // started Activity.
      // This ensures that navigating backward from the Activity leads out of
      // your application to the Home screen.
      TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
      // Adds the back stack for the Intent (but not the Intent itself)
      stackBuilder.addParentStack(ChatActivity.class);
      // Adds the Intent that starts the Activity to the top of the stack
      stackBuilder.addNextIntent(resultIntent);
      PendingIntent resultPendingIntent =
          stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
      mBuilder.setContentIntent(resultPendingIntent);
      NotificationManager mNotificationManager =
          (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
      int mId = 0;
      Notification nf = mBuilder.build();
      nf.defaults = Notification.DEFAULT_ALL;
      nf.flags = Notification.FLAG_AUTO_CANCEL;

      // mId allows you to update the notification later on.
      mNotificationManager.notify(mId, nf);
    }
 /**
  * This method sends a notification to NotificationManager to display an error dialog indicating
  * low disk space and launch the Installer application
  */
 private final void sendNotification() {
   if (localLOGV) Slog.i(TAG, "Sending low memory notification");
   // log the event to event log with the amount of free storage(in bytes) left on the device
   EventLog.writeEvent(EventLogTags.LOW_STORAGE, mFreeMem);
   //  Pack up the values and broadcast them to everyone
   Intent lowMemIntent =
       new Intent(
           Environment.isExternalStorageEmulated()
               ? Settings.ACTION_INTERNAL_STORAGE_SETTINGS
               : Intent.ACTION_MANAGE_PACKAGE_STORAGE);
   lowMemIntent.putExtra("memory", mFreeMem);
   lowMemIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   NotificationManager mNotificationMgr =
       (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
   CharSequence title =
       mContext.getText(com.android.internal.R.string.low_internal_storage_view_title);
   CharSequence details =
       mContext.getText(com.android.internal.R.string.low_internal_storage_view_text);
   PendingIntent intent =
       PendingIntent.getActivityAsUser(mContext, 0, lowMemIntent, 0, null, UserHandle.CURRENT);
   Notification notification = new Notification();
   notification.icon = com.android.internal.R.drawable.stat_notify_disk_full;
   notification.tickerText = title;
   notification.flags |= Notification.FLAG_NO_CLEAR;
   notification.setLatestEventInfo(mContext, title, details, intent);
   mNotificationMgr.notifyAsUser(null, LOW_MEMORY_NOTIFICATION_ID, notification, UserHandle.ALL);
   mContext.sendStickyBroadcastAsUser(mStorageLowIntent, UserHandle.ALL);
 }
 @Override
 public void onFail(DownloadTask task) throws RemoteException {
   // TODO Auto-generated method stub
   if (mContext != null && task != null) {
     if (mNotificationManager != null) {
       // 移除之前的通知
       mNotificationManager.cancel(NOTIFY_TAG, (int) task.getId());
       // 更新下载信息
       if (mShowNotification && mNotification != null) {
         mNotification.tickerText = mFailTickerText;
         mNotification.contentIntent = mPendingIntent;
         //					mNotificationRemoteViews.setTextViewText(R.id.downloadTextView, mFailText);
         //					mNotification.contentView = mNotificationRemoteViews;
         mNotification.setLatestEventInfo(
             mContext,
             mFailText,
             mProgressText + " " + task.getAlreadyDownloadPercent() + "%",
             mPendingIntent);
         mNotification.flags = Notification.FLAG_AUTO_CANCEL;
         //					mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification);
         if (mNotification.contentView != null) {
           mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification);
         }
       }
     }
   }
 }
  /** Sets up a notification shortcut in the system bar */
  public static void setupNotification() {
    Context context = ApplicationContext.getInstance();
    String notificationService = Context.NOTIFICATION_SERVICE;
    mNotificationManager = (NotificationManager) context.getSystemService(notificationService);
    Intent notificationIntent = new Intent(context, MainFragmentActivity.class);
    PendingIntent contentIntent =
        PendingIntent.getActivity(
            context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder mBuilder;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
      mBuilder =
          new NotificationCompat.Builder(ApplicationContext.getInstance())
              .setSmallIcon(R.drawable.ic_stat_notification)
              .setContentTitle(context.getResources().getText(R.string.app_name))
              .setContentText(context.getResources().getText(R.string.go_to_app))
              .setWhen(0);
    else
      mBuilder =
          new NotificationCompat.Builder(ApplicationContext.getInstance())
              .setSmallIcon(R.drawable.ic_stat_notification)
              .setContentTitle(context.getResources().getText(R.string.app_name))
              .setContentText(context.getResources().getText(R.string.go_to_app));

    mBuilder.setContentIntent(contentIntent);
    // mId allows you to update the notification later on.
    int mId = 1;
    Notification shortcutNotification = mBuilder.build();
    shortcutNotification.flags |= Notification.FLAG_ONGOING_EVENT;
    mNotificationManager.notify(mId, shortcutNotification);

    ApplicationContext.getInstance().notificationIsShowing = true;
  }
 @Override
 public void onCancel(DownloadTask task) throws RemoteException {
   if (task != null) {
     sendBroadcastingToAppCenter(task);
     stopAppGameNetLog(task);
     if (mNotificationManager != null) {
       if (mShowNotification && mNotification != null) {
         // 更新下载信息
         mNotification.tickerText = mCancelTickerText;
         mNotification.contentIntent = mPendingIntent;
         mNotification.flags = Notification.FLAG_AUTO_CANCEL;
         //					mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification);
         if (mNotification.contentView != null) {
           mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification);
         }
       }
     }
     String filePath = task.getSaveFilePath();
     if (TextUtils.isEmpty(filePath)) {
       return;
     }
     File saveFile = new File(filePath);
     if (saveFile.exists()) {
       saveFile.delete();
     }
   }
 }
Ejemplo n.º 24
0
  public void createNotification() {
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notification = new Notification();
    notification.icon = R.drawable.ic_launcher;
    // // 这个参数是通知提示闪出来的值.
    notification.tickerText = "开始下载";
    //
    updateIntent = new Intent(this, MainActivity.class);
    pendingIntent = PendingIntent.getActivity(this, 0, updateIntent, 0);
    //
    // // 这里面的参数是通知栏view显示的内容
    notification.setLatestEventInfo(this, app_name, "下载:0%", pendingIntent);
    //
    notificationManager.notify(notification_id, notification);

    /** * 在这里我们用自定的view来显示Notification */
    contentView = new RemoteViews(getPackageName(), R.layout.notification_item);
    contentView.setTextViewText(R.id.notificationTitle, "正在下载");
    contentView.setTextViewText(R.id.notificationPercent, "0%");
    contentView.setProgressBar(R.id.notificationProgress, 100, 0, false);

    notification.contentView = contentView;

    updateIntent = new Intent(this, MainActivity.class);
    updateIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    pendingIntent = PendingIntent.getActivity(this, 0, updateIntent, 0);

    notification.contentIntent = pendingIntent;

    notificationManager.notify(notification_id, notification);
  }
  public void makeNotification(
      String title, String content, int extraNotificationFlag, Intent intent) {
    int notificationId = 0;
    int notificationIcon = 0;
    if ((extraNotificationFlag & Notification.FLAG_ONGOING_EVENT) != 0) {
      notificationIcon = R.drawable.icon;
      notificationId = ON_GOING_NOTIFICATION_ID;
    } else {
      notificationIcon = R.drawable.message_sent;
      notificationId = NOTIFICATION_ID;
      if (++NOTIFICATION_ID > MAX_NOTIFICATION_ID) {
        NOTIFICATION_ID = INIT_NOTIFICATION_ID;
      }
    }

    Notification newNotification =
        new Notification(notificationIcon, content, System.currentTimeMillis());
    newNotification.flags = newNotification.flags | extraNotificationFlag;

    // start the passer activity to cancel the notification
    PendingIntent correspondingIntent = PendingIntent.getActivity(context, 0, intent, 0);

    newNotification.setLatestEventInfo(context, title, content, correspondingIntent);

    notificationManager.notify(notificationId, newNotification);
  }
Ejemplo n.º 26
0
  private void showNotification(Context context) {
    nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    Intent intent = new Intent(context, MoodPopUp.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra(Constants.REMINDER_ID, reminderID);
    int notifRequestCode = 6000 + requestCode;
    PendingIntent pendingIntent =
        PendingIntent.getActivity(
            context, notifRequestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    Notification.Builder notificationBuilder =
        new Notification.Builder(context)
            .setContentIntent(pendingIntent)
            .setContentText(context.getString(R.string.popup_title))
            .setSmallIcon(R.drawable.ic_mood_notification_icon)
            .setWhen(System.currentTimeMillis())
            .setTicker(context.getString(R.string.popup_title))
            .setContentTitle(context.getString(R.string.popup_mood_text))
            .setDefaults(Notification.DEFAULT_SOUND)
            .setAutoCancel(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      notificationBuilder.setColor(context.getResources().getColor(R.color.darkPurple));
    }

    Notification notification = notificationBuilder.build();
    notification.deleteIntent =
        PendingIntent.getBroadcast(context, notifRequestCode, getDeleteIntent(context), 0);
    Log.i(TAG, "Notified. reminder ID = " + reminderID);
    nm.notify(notifRequestCode, notification);
  }
Ejemplo n.º 27
0
  private void updateNotification(Context context, Alarm alarm, int timeout) {
    NotificationManager nm = getNotificationManager(context);

    // If the alarm is null, just cancel the notification.
    if (alarm == null) {
      if (Log.LOGV) {
        Log.v("Cannot update notification for killer callback");
      }
      return;
    }

    // Launch SetAlarm when clicked.
    Intent viewAlarm = new Intent(context, SetAlarm.class);
    viewAlarm.putExtra(Alarms.ALARM_ID, alarm.id);
    PendingIntent intent = PendingIntent.getActivity(context, alarm.id, viewAlarm, 0);

    // Update the notification to indicate that the alert has been
    // silenced.
    String label = alarm.getLabelOrDefault(context);
    Notification n = new Notification(R.drawable.stat_notify_alarm, label, alarm.time);
    n.setLatestEventInfo(
        context, label, context.getString(R.string.alarm_alert_alert_silenced, timeout), intent);
    n.flags |= Notification.FLAG_AUTO_CANCEL;
    // We have to cancel the original notification since it is in the
    // ongoing section and we want the "killed" notification to be a plain
    // notification.
    nm.cancel(alarm.id);
    nm.notify(alarm.id, n);
  }
Ejemplo n.º 28
0
  @SuppressWarnings("deprecation")
  @Override
  public void onReceive(Context ctxt, Intent intent) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctxt);
    boolean useNotification = prefs.getBoolean("use_notification", true);

    if (useNotification) {
      NotificationManager mgr =
          (NotificationManager) ctxt.getSystemService(Context.NOTIFICATION_SERVICE);
      Notification note =
          new Notification(
              android.R.drawable.stat_notify_chat,
              "It's time for lunch!",
              System.currentTimeMillis());
      PendingIntent i =
          PendingIntent.getActivity(ctxt, 0, new Intent(ctxt, AlarmActivity.class), 0);

      note.setLatestEventInfo(ctxt, "LunchList", "It's time for lunch! Aren't you hungry?", i);
      note.flags |= Notification.FLAG_AUTO_CANCEL;

      mgr.notify(NOTIFY_ME_ID, note);
    } else {
      Intent i = new Intent(ctxt, AlarmActivity.class);

      i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

      ctxt.startActivity(i);
    }
  }
Ejemplo n.º 29
0
 @Override
 protected void onHandleIntent(Intent intent) {
   if (notificationManager == null)
     notificationManager =
         (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
   Intent notificationIntent = new Intent(this, SplashActivity.class);
   notificationIntent.setAction(Intent.ACTION_MAIN);
   notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
   PendingIntent pendingIntent2 = PendingIntent.getActivity(this, 0, notificationIntent, 0);
   // 通过Notification.Builder来创建通知,注意API Level
   // API11之后才支持
   Notification notify2 =
       new Notification.Builder(this)
           .setSmallIcon(
               R.drawable
                   .ic_launcher) // 设置状态栏中的小图片,尺寸一般建议在24×24,这个图片同样也是在下拉状态栏中所显示,如果在那里需要更换更大的图片,可以使用setLargeIcon(Bitmap
           // icon)
           .setTicker("TickerText:" + "您有新短消息,请注意查收!") // 设置在status
           // bar上显示的提示文字
           .setContentTitle("Notification Title") // 设置在下拉status
           // bar后Activity,本例子中的NotififyMessage的TextView中显示的标题
           .setContentText("This is the notification message") // TextView中显示的详细内容
           .setContentIntent(pendingIntent2) // 关联PendingIntent
           .setNumber(
               1) // 在TextView的右方显示的数字,可放大图片看,在最右侧。这个number同时也起到一个序列号的左右,如果多个触发多个通知(同一ID),可以指定显示哪一个。
           .getNotification(); // 需要注意build()是在API level
   // 16及之后增加的,在API11中可以使用getNotificatin()来代替
   notify2.flags |= Notification.FLAG_AUTO_CANCEL;
   notificationManager.notify(NOTIFICATION_FLAG, notify2);
 }
  @Override
  protected void onMessage(Context arg0, Intent i) {
    String tvid = i.getStringExtra("tvid");
    Log.i("Message Received", tvid);
    String rtitle = i.getStringExtra("title");
    Log.i("Message Received", rtitle);
    String status = i.getStringExtra("status");
    Log.i("Message Received", status);
    String rely = i.getStringExtra("rely");
    Log.i("Message Received", rely);
    String epname = i.getStringExtra("epname");
    Log.i("Message Received", epname);
    String epinfo = i.getStringExtra("epinfo");
    Log.i("Message Received", epinfo);
    String epdate = i.getStringExtra("epdate");
    Log.i("Message Received", epdate);
    Databasehelper dbh = new Databasehelper(this);
    dbh.update(tvid, rtitle, status, rely, epname, epinfo, epdate);

    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    intent = new Intent(this, ShowSeries.class);
    PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
    String body = tvid;
    String title = "Message Received";
    Notification n = new Notification(R.drawable.ic_launcher, body, System.currentTimeMillis());
    n.setLatestEventInfo(getApplicationContext(), title, body, pi);
    n.defaults = Notification.DEFAULT_ALL;
    n.flags = Notification.FLAG_AUTO_CANCEL;
    nm.notify(NotifyId, n);
  }