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);
  }
  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);
  }
  @Override
  public void onCreate() {

    HunyDewZLogger.startTrace("fulfillerf");

    super.onCreate();

    fulfillerLocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    LocationListener fulfillerLocListener = new HunyDooLocationListener();

    // if (LocationManager.GPS_PROVIDER!=null)
    //   hdLocProvider = LocationManager.GPS_PROVIDER;

    Criteria hdCrit = new Criteria();
    hdCrit.setAccuracy(Criteria.ACCURACY_COARSE);
    hdLocProvider = fulfillerLocManager.getBestProvider(hdCrit, true);
    // ms  // meter
    fulfillerLocManager.requestLocationUpdates(hdLocProvider, 60000, 100, fulfillerLocListener);

    //	    Location currentLocation = fulfillerLocManager.getLastKnownLocation(hdLocProvider);

    // Instantiate the notification
    int iconReached =
        R.drawable.push_pin; // TBD - eventually this will be small size launcher Icon
    String textReachedLoca = getResources().getText(R.string.notiMesg).toString();
    long whenReached = System.currentTimeMillis();
    hdLocaReachedNotification = new Notification(iconReached, textReachedLoca, whenReached);

    hdLocaReachedNotification.defaults |= Notification.DEFAULT_SOUND;
    hdLocaReachedNotification.defaults |= Notification.DEFAULT_LIGHTS;
    hdLocaReachedNotification.defaults |= Notification.DEFAULT_VIBRATE;
    hdLocaReachedNotification.audioStreamType = AudioManager.STREAM_NOTIFICATION;

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

    // Flashing Lights
    hdLocaReachedNotification.ledARGB = 0xff00ff00;
    hdLocaReachedNotification.ledOnMS = 300;
    hdLocaReachedNotification.ledOffMS = 1000;
    hdLocaReachedNotification.flags |= Notification.FLAG_SHOW_LIGHTS;

    // define the notification's expanded message and intent
    CharSequence contentTitle = getResources().getText(R.string.notiTitle);
    CharSequence contentText = getResources().getText(R.string.notiMesg);
    Intent notificationIntent = new Intent(this, HunyDewAAStartsHere.class);

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

    hdLocaReachedNotification.setLatestEventInfo(
        getApplicationContext(), contentTitle, contentText, contentIntent);

    // now start the service
    startFulfillerService();

    if (MAIN_ACTIVITY != null) {

      Log.i(getClass().getSimpleName(), "MyService Started");
    }
  }
  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);
  }
  /** Show a notification informing the user when a deck is ready to be used */
  private void showNotification(String deckTitle, String deckFilename) {
    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    Resources res = getResources();

    // Set the icon, scrolling text and timestamp
    Notification notification =
        new Notification(
            R.drawable.anki, res.getString(R.string.download_finished), System.currentTimeMillis());

    String deckPath = mDestination + "/" + deckFilename + ".anki";
    //        Intent loadDeckIntent = StudyOptions.getLoadDeckIntent(this, deckPath);
    // The PendingIntent to launch our activity if the user selects this notification
    //        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, loadDeckIntent, 0);

    // Set the info for the views that show in the notification panel
    //        notification.setLatestEventInfo(this, deckTitle,
    // res.getString(R.string.deck_downloaded), contentIntent);

    // Clear the notification when the user selects it
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    // Vibrate
    notification.defaults |= Notification.DEFAULT_VIBRATE;

    // Show a blue light
    notification.ledARGB = 0xff0000ff;
    notification.ledOnMS = 500;
    notification.ledOffMS = 1000;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;

    // Send the notification
    Log.i(AnkiDroidApp.TAG, "Sending notification...");
    mNotificationManager.notify(getNextNotificationId(), notification);
  }
 private void setFlag(int mask, boolean value) {
   if (value) {
     mNotification.flags |= mask;
   } else {
     mNotification.flags &= ~mask;
   }
 }
  private void sendNotification() {

    NotificationManager mNotificationManager =
        (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    Intent mIntent = new Intent(this, NotificationExampleActivity.class);

    PendingIntent contentIntent =
        PendingIntent.getActivity(this, 1, mIntent, PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder mBuilder;

    mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle("This is title")
            .setStyle(new NotificationCompat.BigTextStyle().bigText("This Description"))
            .setContentText("This is sort desc");
    mBuilder.setContentIntent(contentIntent);
    Notification notification = mBuilder.build();

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;

    mNotificationManager.notify(120, notification);
  }
 private void setFlag(int paramInt, boolean paramBoolean) {
   Notification localNotification;
   if (!paramBoolean) {
     localNotification = this.mNotification;
     localNotification.flags &= (paramInt ^ 0xFFFFFFFF);
   } else {
     localNotification = this.mNotification;
     localNotification.flags = (paramInt | localNotification.flags);
   }
 }
  @Override
  public void onCreate() {
    super.onCreate();

    // Create MediaPlayer
    __mediaPlayer = new MediaPlayer();

    Log.i("AudioService", "Created the __mediaPlayer.");

    // When called OnCompletionListener().
    __mediaPlayer.setOnCompletionListener(
        new OnCompletionListener() {
          public void onCompletion(MediaPlayer arg0) {
            __state = 0;
          }
        });

    __mediaPlayer.setOnSeekCompleteListener(
        new OnSeekCompleteListener() {
          @Override
          public void onSeekComplete(MediaPlayer mediaPlayer) {
            Log.d(
                "VID_PLAYER",
                "Seek Complete. Current Position: " + mediaPlayer.getCurrentPosition());
            mediaPlayer.start();
          }
        });

    IntentFilter receiverFilter = new IntentFilter();
    receiverFilter.addAction(Intent.ACTION_POWER_CONNECTED);
    registerReceiver(__musicReceiver, receiverFilter);

    NotificationManager noficicationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.smile)
            .setContentTitle("Playing the music.")
            .setContentText("NiceMusicApp");

    Intent intent = new Intent(this, com.web2korea.nicemusicapp.MusicListActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    builder.setContentIntent(pendingIntent);
    Notification notification = builder.build();

    notification.flags = Notification.FLAG_ONLY_ALERT_ONCE;
    // notification.flags = Notification.FLAG_ONGOING_EVENT;
    notification.flags = Notification.FLAG_AUTO_CANCEL;

    noficicationManager.notify(NOTIFICATION_REMOVE, notification);
  }
 private void setFlag(int i, boolean flag)
 {
     if (flag)
     {
         Notification notification = mNotification;
         notification.flags = notification.flags | i;
         return;
     } else
     {
         Notification notification1 = mNotification;
         notification1.flags = notification1.flags & ~i;
         return;
     }
 }
Beispiel #12
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);
  }
  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);
  }
 @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 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();
    }
  }
  // send notification to Notification bar, open notification bar, will stay there,
  // but if any press, will clear all facebook notifications
  private void sendNotification(String title, String content) {
    WakeLock wl =
        pownermMgr.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "SCREEN_BRIGHT_WAKE_LOCK");
    wl.acquire(10 * 1000);

    if (orm.getNotificationVibrate()) {
      final Vibrator vib =
          (android.os.Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
      vib.vibrate(2 * 1000);
    }

    Notification notification = new Notification();
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.flags |= Notification.DEFAULT_SOUND;
    notification.ledARGB = 0xff00ff00;
    notification.ledOnMS = 500;
    notification.ledOffMS = 2000;

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

    notification.defaults |= Notification.DEFAULT_SOUND;
    notify.notifyNotifications(
        title,
        content,
        R.drawable.facebook_logo,
        Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE,
        notification);
  }
 /**
  * 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);
 }
Beispiel #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);
    }
  // Prepare notification data and display it.
  private void doNotification(Context context, Long messageId, Bitmap srcPhoto) {

    ChatMsgBaseInfo message = WalkArroundMsgManager.getInstance(context).getMessageById(messageId);

    if (message == null) {
      return;
    }

    ContactInfo contact =
        ContactsManager.getInstance(context).getContactByUsrObjId(message.getContact());

    Intent intent = new Intent();
    intent.setClass(context.getApplicationContext(), BuildMessageActivity.class);
    intent.putExtra(BuildMessageActivity.INTENT_RECEIVER_EDITABLE, false);
    intent.putExtra(BuildMessageActivity.INTENT_CONVERSATION_RECEIVER, message.getContact());
    intent.putExtra(BuildMessageActivity.INTENT_CONVERSATION_THREAD_ID, message.getMsgThreadId());
    intent.putExtra(BuildMessageActivity.INTENT_CONVERSATION_TYPE, message.getChatType());

    // TODO: contact should write to DB & we should crate a content provider for those contacts.
    if (contact != null) {
      intent.putExtra(BuildMessageActivity.INTENT_CONVERSATION_DISPLAY_NAME, contact.getUsername());
    }

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent =
        PendingIntent.getActivity(
            context, (int) message.getMsgThreadId(), intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // If the contact is null, set the user name as empty.
    String displayName = (contact == null ? "" : contact.getUsername());
    message.setData(MessageUtil.getDisplayStr(context, displayName, message));
    Notification notification = new Notification();
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    notification.icon = R.drawable.msg_notify_icon;

    // TODO: Add Emoji parser later.
    notification.tickerText = EmojiParser.getInstance(context).getSmileyText(message.getData());
    notification.tickerText = message.getData();

    if (Build.VERSION.SDK_INT == 19) {
      contentIntent.cancel();
      contentIntent =
          PendingIntent.getActivity(
              context, (int) message.getMsgThreadId(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }
    notification.contentIntent = contentIntent;
    notification.contentView = new RemoteViews(context.getPackageName(), R.layout.msg_notify_panel);
    //        notification.defaults=Notification.DEFAULT_SOUND;
    initNotifyView(context, notification.contentView, message, contact, srcPhoto);
    try {
      String number = (contact == null ? DEFAULT_NOTIFICATION_ID : contact.getMobilePhoneNumber());
      int startPos = number.length() > 5 ? number.length() - 5 : 0;
      int id = Integer.parseInt(number.substring(startPos));
      NotificationManager manager =
          (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
      manager.notify(number, id, notification);
    } catch (NumberFormatException e) {
      sLogger.e("notification NumberFormatException:" + e.getMessage());
    }
  }
 @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();
     }
   }
 }
Beispiel #24
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);
    }
  }
  /**
   * 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);
  }
  /** Shows the timer notification */
  private void showNotification() {
    mNotification = new Notification(R.drawable.icon, null, System.currentTimeMillis());
    mNotification.flags = Notification.FLAG_ONGOING_EVENT;

    // Use start foreground as user would notice if timer was stopped
    startForeground(TIMER_NOTIFICATION, mNotification);
  }
  /** 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);
  }
 @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);
 }
  /** 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);
  }
Beispiel #30
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);
 }