Beispiel #1
1
  private void showNotification() {
    try {
      // add notification to status bar
      NotificationCompat.Builder builder =
          new NotificationCompat.Builder(this)
              .setSmallIcon(R.drawable.icon)
              .setLargeIcon(AudioUtil.getCover(this, mCurrentMedia, 64))
              .setContentTitle(mCurrentMedia.getTitle())
              .setTicker(mCurrentMedia.getTitle() + " - " + mCurrentMedia.getArtist())
              .setContentText(
                  Util.isJellyBeanOrLater()
                      ? mCurrentMedia.getArtist()
                      : mCurrentMedia.getSubtitle())
              .setContentInfo(mCurrentMedia.getAlbum())
              .setAutoCancel(false)
              .setOngoing(true);

      Intent notificationIntent = new Intent(this, AudioPlayerActivity.class);
      notificationIntent.setAction(Intent.ACTION_MAIN);
      notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
      notificationIntent.putExtra(START_FROM_NOTIFICATION, true);
      PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

      builder.setContentIntent(pendingIntent);
      startForeground(3, builder.build());
    } catch (NoSuchMethodError e) {
      // Compat library is wrong on 3.2
      // http://code.google.com/p/android/issues/detail?id=36359
      // http://code.google.com/p/android/issues/detail?id=36502
    }
  }
Beispiel #2
0
  private Notification getForegroundNotification(int allowed, int blocked) {
    Intent main = new Intent(this, ActivityMain.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_security_white_24dp)
            .setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_started))
            .setContentIntent(pi)
            .setCategory(Notification.CATEGORY_STATUS)
            .setVisibility(Notification.VISIBILITY_SECRET)
            .setPriority(Notification.PRIORITY_MIN)
            .setColor(tv.data)
            .setOngoing(true)
            .setAutoCancel(false);

    if (allowed > 0 || blocked > 0) {
      NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
      notification.bigText(getString(R.string.msg_started));
      notification.setSummaryText(getString(R.string.msg_packages, allowed, blocked));
      return notification.build();
    } else return builder.build();
  }
  /**
   * Create and show a simple notification containing the received GCM message.
   *
   * @param message GCM message received.
   */
  private void sendNotification(String message, String extra) {
    Intent intent = new Intent("com.ibm.bluebridge.pushnotification");
    try {
      JSONObject data = new JSONObject(extra);
      Iterator<String> itr = data.keys();
      while (itr.hasNext()) {
        String key = itr.next();
        intent.putExtra(key, data.getString(key));
      }
    } catch (JSONException e) {
      Log.e(TAG, "Cannot parse data, no extra set to Notification");
    }
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent =
        PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.logo)
            .setContentTitle("BlueBridge")
            .setContentText(message)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
  }
  private void showNotification(String text) {
    // http://stackoverflow.com/questions/13602190/java-lang-securityexception-requires-vibrate-permission-on-jelly-bean-4-2
    try {
      Intent notificationIntent = new Intent(MainActivity.this, MainActivity.class);
      notificationIntent.putExtra(SMTHApplication.SERVICE_NOTIFICATION_MESSAGE, text);
      // http://stackoverflow.com/questions/26608627/how-to-open-fragment-page-when-pressed-a-notification-in-android
      notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
      PendingIntent resultPendingIntent =
          PendingIntent.getActivity(
              MainActivity.this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

      NotificationCompat.Builder mBuilder =
          new NotificationCompat.Builder(this)
              .setSmallIcon(R.drawable.ic_launcher)
              .setContentTitle("zSMTH提醒")
              .setWhen(System.currentTimeMillis())
              .setAutoCancel(true)
              .setOnlyAlertOnce(true)
              .setDefaults(Notification.DEFAULT_VIBRATE)
              .setContentText(text)
              .setContentIntent(resultPendingIntent);
      Notification notification = mBuilder.build();

      NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
      mNotifyMgr.notify(notificationID, notification);
    } catch (Exception se) {
      Log.e(TAG, "showNotification: " + se.toString());
    }
  }
  public void launchNotification(Context context, Events event) throws Exception {
    NotificationManager nManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    Log.e("Notification", "Notification up");

    NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_event_white_36dp)
            .setContentTitle(context.getString(R.string.app_name))
            .setContentText(
                context.getString(R.string.notification1)
                    + " "
                    + event.getTitle()
                    + context.getString(R.string.notification2));

    Intent i = new Intent(context, EventFragment.class);
    i.putExtra("image", event.getImage());
    i.putExtra("title", event.getTitle());
    i.putExtra("description", event.getDescription());
    i.putExtra("date", event.getDate());
    i.putExtra("price", event.getPrice());
    i.putExtra("time", event.getTime());
    i.putExtra("notification", 0);

    PendingIntent contentIntent =
        PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

    notificationBuilder.setContentIntent(contentIntent);
    notificationBuilder.setAutoCancel(true);

    nManager.notify(123, notificationBuilder.build());
  }
  public void notificar(
      int idNotificacao,
      String titulo,
      String texto,
      String ticker,
      Class classe,
      Parada parada,
      int icone) {
    mBuilder.setContentTitle(titulo).setContentText(texto).setTicker(ticker);
    mBuilder.setSmallIcon(icone);
    Intent resultIntent = new Intent(con, classe);

    resultIntent.putExtra("nomeparada", parada.getNome());
    resultIntent.putExtra("codigoparada", parada.getCodigoParada());

    SimpleDateFormat dateFormat_hora = new SimpleDateFormat("HH:mm:ss");
    Date data = new Date();
    Calendar cal = Calendar.getInstance();
    cal.setTime(data);
    Date data_atual = cal.getTime();
    String hora_atual = dateFormat_hora.format(data_atual);

    resultIntent.putExtra("infotempoatual", hora_atual);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(con);
    stackBuilder.addParentStack(classe);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    mNotificationManager.notify(idNotificacao, mBuilder.build());
  }
  public void buildNotification() {
    int notificationId = 2;

    //                    Intent viewIntent = new Intent(this, MainActivity.class);
    //                    PendingIntent viewPendingIntent =
    //                            PendingIntent.getActivity(this, 1000, viewIntent, 0);
    //
    //        Intent camIntent = new Intent(this, MySenderService.class);
    //        PendingIntent camPendingIntent = PendingIntent.getService(this, 0, camIntent, 0);

    Log.v(TAG, "Twitter Notification Start");

    NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(MyWearReceiverService.this)
            .setSmallIcon(R.drawable.hero)
            .setContentTitle("Twitter")
            .setContentText("Tweet Sent");
    // .setContentIntent(camPendingIntent)
    // .addAction(R.drawable.ic_camera_enhance_black_48dp, "Open Camera", camPendingIntent);

    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    // Build the notification and issues it with notification manager.
    notificationManager.notify(notificationId, notificationBuilder.build());
    Log.v(TAG, "Twitter Notification Build Completed");
  }
Beispiel #8
0
  public void updateNotification() {
    if (!Preferences.isNotificationEnabled() || !playServicesAvailable) return;

    String title = null;
    String subtitle = null;
    long time = 0;

    if ((this.lastPublishedLocation != null) && Preferences.isNotificationLocationEnabled()) {
      time = this.lastPublishedLocationTime.getTime();

      if ((this.lastPublishedLocation.getGeocoder() != null)
          && Preferences.isNotificationGeocoderEnabled()) {
        title = this.lastPublishedLocation.toString();
      } else {
        title = this.lastPublishedLocation.toLatLonString();
      }
    } else {
      title = this.context.getString(R.string.app_name);
    }

    subtitle =
        ServiceLocator.getStateAsString(this.context)
            + " | "
            + ServiceBroker.getStateAsString(this.context);

    notificationBuilder.setContentTitle(title);
    notificationBuilder
        .setSmallIcon(R.drawable.ic_notification)
        .setContentText(subtitle)
        .setPriority(android.support.v4.app.NotificationCompat.PRIORITY_MIN);
    if (time != 0) notificationBuilder.setWhen(this.lastPublishedLocationTime.getTime());

    this.notification = notificationBuilder.build();
    this.context.startForeground(Defaults.NOTIFCATION_ID, this.notification);
  }
  private Notification makeNotification(
      PendingIntent pendingIntent,
      String title,
      String content,
      String tickerText,
      int iconId,
      boolean ring,
      boolean vibrate) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder
        .setContentTitle(title)
        .setContentText(content)
        .setAutoCancel(true)
        .setContentIntent(pendingIntent)
        .setTicker(tickerText)
        .setSmallIcon(iconId);
    int defaults = Notification.DEFAULT_LIGHTS;
    if (vibrate) {
      defaults |= Notification.DEFAULT_VIBRATE;
    }
    if (ring) {
      defaults |= Notification.DEFAULT_SOUND;
    }
    builder.setDefaults(defaults);

    return builder.build();
  }
  private void handleErrorInBackground(ConnectionResult connectionResult, int startId) {
    if (!connectionResult.hasResolution()) {
      // Show the localized error notification
      GoogleApiAvailability.getInstance()
          .showErrorNotification(this, connectionResult.getErrorCode());
      return;
    }
    // The failure has a resolution. Resolve it.
    // Called typically when the app is not yet authorized, and an
    // authorization dialog is displayed to the user.
    Intent resultIntent = new Intent(this, WorkoutListActivity.class);
    resultIntent.putExtra(WorkoutListActivity.EXTRA_PLAY_API_CONNECT_RESULT, connectionResult);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(WorkoutListActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(this)
            .setContentTitle(
                getResources().getString(R.string.permission_needed_play_service_title))
            .setContentText(getResources().getString(R.string.permission_needed_play_service))
            .setSmallIcon(R.drawable.common_ic_googleplayservices)
            .setContentIntent(resultPendingIntent)
            .setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      notificationBuilder.setCategory(Notification.CATEGORY_ERROR);
    }

    ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE))
        .notify(Constants.NOTIFICATION_PLAY_INTERACTION, notificationBuilder.build());
    stopSelfResult(startId);
  }
Beispiel #11
0
  private void createNotification() {
    Log.v(this.toString(), "createNotification");
    //
    notificationBuilder = new NotificationCompat.Builder(this.context);

    Intent resultIntent = new Intent(this.context, ActivityLauncher.class);
    resultIntent.setAction("android.intent.action.MAIN");
    resultIntent.addCategory("android.intent.category.LAUNCHER");

    resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent resultPendingIntent =
        PendingIntent.getActivity(this.context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    notificationBuilder.setContentIntent(resultPendingIntent);

    this.notificationIntent =
        ServiceProxy.getPendingIntentForService(
            this.context,
            ServiceProxy.SERVICE_LOCATOR,
            Defaults.INTENT_ACTION_PUBLISH_LASTKNOWN,
            null);
    notificationBuilder.addAction(
        R.drawable.ic_action_upload,
        this.context.getString(R.string.publish),
        this.notificationIntent);
    updateNotification();
  }
Beispiel #12
0
 @Override
 public void onCancel() {
   mGoogleApiClient.disconnect();
   String title = getString(R.string.app_name);
   // initialize the notification
   NotificationCompat.Builder mBuilder =
       new NotificationCompat.Builder(getApplicationContext())
           .setSmallIcon(R.mipmap.ic_launcher_logo)
           .setContentTitle(title)
           .setContentText(getString(R.string.alarm_cancelled))
           .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
           .setAutoCancel(true);
   Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class);
   PendingIntent resultPendingIntent =
       PendingIntent.getActivity(
           getApplicationContext(), 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
   mBuilder.setContentIntent(resultPendingIntent);
   NotificationManager mNotificationManager =
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
   //  allows you to update the notification later on.
   if (!declined) {
     mNotificationManager.notify(AlarmNotifier.notificationID, mBuilder.build());
     String text = getString(R.string.alarm_cancelled);
     Toast toast = Toast.makeText(getApplicationContext(), text, Toast.LENGTH_LONG);
     toast.show();
   }
   finish();
 }
Beispiel #13
0
  public void showNotification(Friend f) {
    Log.i(TAG, "notification");
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("Tracing of \n" + f.getPseudo())
            .setContentText(f.getFirstName() + "," + f.getLastName());
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, GoogleMapActivity.class);

    f.setVisibleInMap(true);
    // resultIntent.putExtra("onePoint", f);
    // 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(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(GoogleMapActivity.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) getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(0, mBuilder.build());
  }
 private void notify(int id) {
   if (mNotificationManager != null) {
     CharSequence text = getText(id);
     mNotifyBuilder.setContentText(text);
     mNotificationManager.notify(mNotifyId, mNotifyBuilder.build());
   }
 }
  @NonNull
  private NotificationCompat.Builder buildBaseNotification(boolean isPhone) {

    final NotificationCompat.Action action = getNotificationAction();

    final String title = titleForActivityType(context);
    final String message = messageForActivityType(context, isPhone);

    final NotificationCompat.Builder builder =
        new NotificationCompat.Builder(context)
            .setSmallIcon(notificationIcon)
            .setDefaults(pomodoroMaster.isOngoing() ? 0 : Notification.DEFAULT_ALL)
            .setOnlyAlertOnce(true)
            .setCategory(NotificationCompat.CATEGORY_ALARM)
            .setPriority(Notification.PRIORITY_MAX)
            .setOngoing(pomodoroMaster.isOngoing())
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setLocalOnly(true)
            .setColor(Utils.getPrimaryColor(context, pomodoroMaster))
            .setContentTitle(title)
            .setContentText(message)
            .addAction(action);
    if (!pomodoroMaster.isOngoing()) {
      builder.setDeleteIntent(
          PendingIntent.getBroadcast(
              context,
              ID_DISMISS,
              new Intent(BaseNotificationService.ACTION_DISMISS),
              PendingIntent.FLAG_UPDATE_CURRENT));
    }
    return builder;
  }
Beispiel #16
0
  private void startNotification() {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager notificationManager = (NotificationManager) getSystemService(ns);

    // Notification notification = new Notification(R.mipmap.ic_launcher, null,
    // System.currentTimeMillis());
    RemoteViews notificationView = new RemoteViews(getPackageName(), R.layout.notificationview);

    // this is the intent that is supposed to be called when the button is clicked
    Intent switchButton = new Intent(this, switchButtonListener.class);
    PendingIntent pendingButtonIntent = PendingIntent.getBroadcast(this, 0, switchButton, 0);
    notificationView.setOnClickPendingIntent(R.id.StartStopButton, pendingButtonIntent);

    // Create Notification using NotificationCompat.Builder
    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(this)
            // Set Icon
            .setSmallIcon(R.drawable.logosmall)
            // Set Ticker Message
            .setTicker(getString(R.string.notificationticker))
            // Set Title
            .setContentTitle(getString(R.string.notificationtitle))
            // Set Text
            .setContentText(getString(R.string.notificationtext))
            // Add an Action Button below Notification
            .addAction(R.mipmap.ic_launcher, "Start", pendingButtonIntent)
            // Set PendingIntent into Notification
            .setContentIntent(pendingButtonIntent)
            // Dismiss Notification
            .setAutoCancel(true);

    notificationManager.notify(0, builder.build());
  }
Beispiel #17
0
  @Override
  protected Notification fillNotification(NotificationCompat.Builder notificationBuilder) {
    NotificationCompat.WearableExtender morePageNotification =
        new NotificationCompat.WearableExtender();

    String firstContent = "", firstTime = "";
    for (TransportManager.Departure d : mDepartures) {
      if (firstTime.isEmpty()) {
        firstTime = d.countDown + "min";
        firstContent = d.servingLine;
      }

      NotificationCompat.Builder pageNotification =
          new NotificationCompat.Builder(mContext)
              .setContentTitle(d.countDown + "min")
              .setContentText(d.servingLine);
      morePageNotification.addPage(pageNotification.build());
    }

    notificationBuilder.setContentTitle(firstTime);
    notificationBuilder.setContentText(firstContent);
    Bitmap bm = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.wear_mvv);
    morePageNotification.setBackground(bm);
    return morePageNotification.extend(notificationBuilder).build();
  }
  public void sendNotification() {
    //
    //      Create an explicit intent for a MainActivity in my app
    Intent mainActivityIntent = new Intent(activity, CallActivity.class);
    NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(activity)
            .setSmallIcon(R.drawable.notification_template_icon_bg)
            .setContentTitle(" Title (test):")
            .setContentText("content")
            .setAutoCancel(true);

    // 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 my application
    // to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(activity);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.class);
    // Add the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(mainActivityIntent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    notificationBuilder.setContentIntent(resultPendingIntent);
    NotificationManager notificationManager =
        (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(TEST_NOTIF_ID, notificationBuilder.build());
  }
  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);
  }
  private void notificar(String titulo, String mensaje, Class<?> actividad) {
    Uri sonido = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(titulo)
            .setContentText(mensaje)
            .setSound(sonido)
            .setAutoCancel(true);

    Intent resultIntent = new Intent(this, actividad);
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);

    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    mNotificationManager.notify(1, mBuilder.build());
  }
Beispiel #21
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);
    }
  /** 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;
  }
  void handleStart(Intent intent, int startId) {
    NotificationManager mManager =
        (NotificationManager) this.getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
    int id = intent.getIntExtra(IntentStrings.SESSION, 0);
    String session_timings = intent.getStringExtra(IntentStrings.SESSION_TIMING);
    DbSingleton dbSingleton = DbSingleton.getInstance();
    Session session = dbSingleton.getSessionById(id);
    Intent intent1 = new Intent(this.getApplicationContext(), SessionDetailActivity.class);
    intent1.putExtra(IntentStrings.SESSION, session.getTitle());
    PendingIntent pendingNotificationIntent =
        PendingIntent.getActivity(
            this.getApplicationContext(), 0, intent1, PendingIntent.FLAG_UPDATE_CURRENT);
    Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_bookmark_white_24dp)
            .setLargeIcon(largeIcon)
            .setContentTitle(session.getTitle())
            .setContentText(session_timings)
            .setAutoCancel(true)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(session_timings))
            .setContentIntent(pendingNotificationIntent);
    intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);

    mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    mManager.notify(1, mBuilder.build());
  }
  public void createNotification(Context context, Bundle extras) {
    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    String appName = getAppName(this);

    Intent notificationIntent = new Intent(this, PushHandlerActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("pushBundle", extras);

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

    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(context)
            .setDefaults(Notification.DEFAULT_ALL)
            .setSmallIcon(context.getApplicationInfo().icon)
            .setWhen(System.currentTimeMillis())
            .setContentTitle(extras.getString("title"))
            .setTicker(extras.getString("title"))
            .setContentIntent(contentIntent);

    String message = extras.getString("message");
    if (message != null) {
      mBuilder.setContentText(message);
    } else {
      mBuilder.setContentText("<missing message content>");
    }

    String msgcnt = extras.getString("msgcnt");
    if (msgcnt != null) {
      mBuilder.setNumber(Integer.parseInt(msgcnt));
    }

    mNotificationManager.notify((String) appName, NOTIFICATION_ID, mBuilder.build());
  }
  public void pushNotification(String msg, Boolean setPendingIntent) {
    mNotificationManager =
        (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    Bitmap icon = BitmapFactory.decodeResource(this.getResources(), R.mipmap.fashion_app_logo);

    Intent notifIntent;
    PendingIntent pendingIntent = null;

    if (setPendingIntent) {
      notifIntent =
          new Intent(this, ClientLoginActivity.class).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
      pendingIntent =
          PendingIntent.getActivity(this, 0, notifIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    }

    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setVisibility(Notification.VISIBILITY_PUBLIC)
            .setLargeIcon(icon)
            .setColor(R.color.primary)
            .setSmallIcon(R.mipmap.ic_trending)
            .setContentTitle("Marshmallow Notification")
            .setContentText(msg)
            .setAutoCancel(true)
            .setPriority(Notification.FLAG_HIGH_PRIORITY)
            .setDefaults(DEFAULT_ALL);

    if (setPendingIntent) {
      mBuilder.setContentIntent(pendingIntent);
    }

    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
  }
  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  private void notifyMe(String titulo, String message) {
    counter++;
    NotificationCompat.Builder mNotifyBuilder;
    NotificationManager mNotificationManager =
        (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotifyBuilder =
        new NotificationCompat.Builder(this)
            .setContentTitle(titulo)
            .setContentText(message)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setDefaults(Notification.DEFAULT_SOUND)
            .setNumber(counter)
            .setAutoCancel(true);
    mNotifyBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));

    mNotificationManager.notify(NOTIFY_ME_ID, mNotifyBuilder.build());

    Intent intent = new Intent(this, HomeActivity.class);
    intent.addFlags(
        Intent.FLAG_ACTIVITY_CLEAR_TOP
            | Intent.FLAG_ACTIVITY_CLEAR_TOP
            | Intent.FLAG_ACTIVITY_NEW_TASK);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(HomeActivity.class);
    stackBuilder.addNextIntent(intent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mNotifyBuilder.setContentIntent(resultPendingIntent);
    mNotificationManager.notify(NOTIFY_ME_ID, mNotifyBuilder.build());
  }
Beispiel #27
0
  private void showEventNotification(int noteId, int icon, String title, String msg) {
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(icon)
            .setContentTitle(title)
            .setContentText(msg)
            .setAutoCancel(true)
            .setDefaults(
                Notification.DEFAULT_LIGHTS
                    | Notification.DEFAULT_SOUND
                    | Notification.DEFAULT_VIBRATE);

    // Creates an explicit intent for an Activity in your app
    Intent intent = new Intent(this, ViewTransactionsActivity.class);

    // 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(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(ViewTransactionsActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(intent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);

    mNM.notify(noteId, mBuilder.build());
  }
Beispiel #28
0
  /**
   * Create and show a simple notification containing the received GCM message.
   *
   * @param message GCM message received.
   */
  private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivity.class);

    // intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.putExtra("from notify", message);

    PendingIntent pendingIntent =
        PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_ic_notification)
            .setContentTitle("BudgetWorld")
            .setContentText(message)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
            .setLights(getResources().getColor(R.color.led), 2000, 2000);

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

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
  }
Beispiel #29
0
  public static void postIModNotification(Context context) {
    NotificationManagerCompat nm = NotificationManagerCompat.from(context);
    if (!MLPreferences.getPrefsApps(context)
        .getBoolean(Common.SHOW_IMOD_RESET_NOTIFICATION, false)) {
      nm.cancel(IMOD_NOTIFICATION_ID);
      return;
    }
    Intent notifyIntent = new Intent(context, ActionActivity.class);
    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    notifyIntent.putExtra(ActionsHelper.ACTION_EXTRA_KEY, R.id.radio_imod_reset);

    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(context)
            .setContentTitle(context.getString(R.string.action_imod_reset))
            .setContentText("")
            .setSmallIcon(R.drawable.ic_apps_24dp)
            .setContentIntent(
                PendingIntent.getActivity(
                    context.getApplicationContext(),
                    0,
                    notifyIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT))
            .setOngoing(true)
            .setAutoCancel(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
      builder.setShowWhen(false);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      builder
          .setPriority(NotificationCompat.PRIORITY_MIN)
          .setCategory(NotificationCompat.CATEGORY_STATUS)
          .setColor(ContextCompat.getColor(context, R.color.accent));
    }
    nm.notify(IMOD_NOTIFICATION_ID, builder.build());
  }
Beispiel #30
0
  // 发送简单通知
  private NotificationCompat.Builder sendSimpleNotification(NotificationCompat.Builder builder) {
    builder.setTicker("通知来了");
    builder.setContentTitle("新消息");
    builder.setContentText("要放假了");

    return builder;
  }