示例#1
1
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  private void showJellyBean() {
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this.activity)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(this.title)
            .setContentText(this.text);

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(activity, activity.getClass());

    // 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(activity);

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

    // 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) activity.getSystemService(Context.NOTIFICATION_SERVICE);

    // mId allows you to update the notification later on.
    mNotificationManager.notify(this.id, mBuilder.build());
  }
示例#2
0
        @Override
        public void onClick(View v) {
          // TODO Auto-generated method stub
          NotificationCompat.Builder mBuilder =
              new NotificationCompat.Builder(context)
                  .setSmallIcon(R.drawable.notification_icon)
                  .setContentTitle("My notification")
                  .setContentText("Hello World! \n hello world!!");
          // Creates an explicit intent for an Activity in your app
          Intent resultIntent = new Intent(context, MainController.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(context);

          // Adds the back stack for the Intent (but not the Intent itself)

          stackBuilder.addParentStack(MainController.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) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
          // mId allows you to update the notification later on.
          mBuilder.setTicker("helo");
          mNotificationManager.notify(1, mBuilder.build());
          mBuilder.setNumber(1).setAutoCancel(true);
        }
  private void sendNotification(String uniqueId) {
    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(this)
            .setContentTitle("New item found")
            .setContentText("An beacon of item " + uniqueId + " is nearby.")
            .setSmallIcon(R.drawable.ic_shopping_basket_24dp)
            .setAutoCancel(true);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack
    stackBuilder.addParentStack(DetailViewActivity.class);
    // Adds the Intent to the top of the stack
    Intent intent = new Intent(this, DetailViewActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    ItemSet itemSet = new ItemSet();
    itemSet.imageList.add(SpecifyViewActivity.setBtImage(uniqueId));
    intent.putExtra("itemSet", itemSet);
    intent.putExtra("name", (String) null);
    intent.putExtra("id", Integer.parseInt(uniqueId));
    intent.setAction(Long.toString(System.currentTimeMillis()));
    stackBuilder.addNextIntent(intent);
    // Gets a PendingIntent containing the entire back stack
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);
    NotificationManager notificationManager =
        (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(Integer.parseInt(uniqueId), builder.build());
  }
  public void showNotification(String title, String text) {
    mId = PreferenceEditor.getInstance().getNotificationCount();
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_setting_light)
            .setContentTitle("Tesseract - " + title)
            .setContentText(text);
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, MainActivity.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(MainActivity.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(mId, mBuilder.build());
  }
示例#5
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 startAsForeground() {
    NotificationManager mNotifyManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);

    Intent resultIntent = new Intent(this, MainActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.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);

    int icon;
    if (Build.VERSION.SDK_INT > 21) icon = R.mipmap.ic_test;
    else icon = R.mipmap.ic_test103;

    mBuilder
        .setContentTitle("Stats Collector")
        .setContentText("Started: " + dateFormat.format(date))
        .setSubText("Session: " + counter)
        .setContentInfo("Interval: " + Settings.interval)
        .setSmallIcon(icon)
        .setColor(Color.parseColor("#78909C"))
        .setCategory(Notification.CATEGORY_SERVICE)
        .setPriority(Notification.PRIORITY_LOW)
        .setContentIntent(resultPendingIntent);
    // .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_test1));

    startForeground(ONGOING_NOTIFICATION_ID, mBuilder.build());

    isForeground = true;
  }
  @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());
  }
  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);
  }
示例#9
0
  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 fireSimpleDefaultPriorityNotification(String notificationTitle, String contentText) {
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.notification_icon)
            .setContentTitle(notificationTitle)
            .setContentText(contentText)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT);
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, MainSetupActivity.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(MainSetupActivity.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);

    // simpleDefaultPriorityNotificationID allows you to update the notification later on.
    mNotificationManager.notify(simpleDefaultPriorityNotificationID, mBuilder.build());
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent i = new Intent(getIntent());
    nome = i.getIntExtra("nome", nome);
    foto = i.getIntExtra("foto", foto);
    id = UUID.fromString(i.getStringExtra("id"));
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setContentTitle(getString(R.string.novo_evento));
    builder.setContentText(getString(nome));
    builder.setTicker(getString(R.string.notificacao_evento));
    builder.setSmallIcon(foto);

    //	TODO colocar rodar mesmo com app fechado
    Intent resultIntent = new Intent(this, EventoPagerActivity.class);
    resultIntent.putExtra(EventoFragment.EXTRA_EVENTO_ID, id);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_ONE_SHOT);
    builder.setContentIntent(resultPendingIntent);
    builder.setAutoCancel(true);
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(idNotificacao, builder.build());

    finish();
  }
示例#12
0
  public void setupNotification() {
    //  From Google: http://developer.android.com/guide/topics/ui/notifiers/notifications.html
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.earphone)
            .setContentTitle("Cloud Player")
            .setContentText(cds.playlist_selected.get(cds.song_index));
    Intent resultIntent = new Intent(this, MainActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    myspref = PreferenceManager.getDefaultSharedPreferences(MainActivity.getInstance());
    SharedPreferences.Editor editor = myspref.edit();
    editor.putBoolean("NOTIFICATION", true);
    editor.apply();

    resultIntent.putExtra("fromNotification", true);

    mNotificationManager.notify(NOTIFY_ID, mBuilder.build());
  }
示例#13
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;
  }
示例#14
0
  private PendingIntent getPendingIntent(Context mContext, ShowUpdate update) {
    Intent intent = new Intent(mContext, ShowDetailsActivity.class);
    intent.putExtra(ShowDetailsActivity.EXTRA_SHOW, update.show());
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
    stackBuilder.addParentStack(ShowDetailsActivity.class);
    stackBuilder.addNextIntent(intent);

    return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
  }
  private PendingIntent buildPendingIntent(Video video) {
    Intent detailsIntent = new Intent(this, PlayerActivity.class);
    detailsIntent.putExtra(Video.INTENT_EXTRA_VIDEO, video);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(VideoDetailsActivity.class);
    stackBuilder.addNextIntent(detailsIntent);
    // Ensure a unique PendingIntents, otherwise all recommendations end up with the same
    // PendingIntent
    detailsIntent.setAction(Long.toString(video.getId()));

    return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
  }
示例#16
0
  private void goToSection() {
    //        Intent sectionIntent = new Intent(this, SingleSheetActivity.class);
    Section sectionaux = Utils.getSectionByID(String.valueOf(value.getRef_sectionID()));
    Sheet sheetAux = Utils.getSheetByID(String.valueOf(sectionaux.getRef_SheetID()));

    Intent singlesheetIntent = new Intent(this, SingleSheetWithTabsActivity.class);
    String rootID = "";
    if (sheetAux != null) {
      rootID = sheetAux.getRef_UserID();
    }
    singlesheetIntent.putExtra("rootID", rootID);
    singlesheetIntent.putExtra("sheetID", String.valueOf(sectionaux.getRef_SheetID()));
    //        sectionIntent.putExtra("sheetID", String.valueOf(sectionaux.getRef_SheetID()));

    Intent home = new Intent(this, RootsActivity.class);
    home.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);

    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(this);
    taskStackBuilder.addNextIntent(home);
    taskStackBuilder.addNextIntent(singlesheetIntent);
    taskStackBuilder.startActivities();
    onBackPressed();
  }
  private void sendNotification() {
    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(this)
            .setContentTitle("LittleHelper")
            .setContentText("An beacon is nearby.")
            .setSmallIcon(R.mipmap.ic_launcher);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addNextIntent(new Intent(this, MainActivity.class));
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);
    NotificationManager notificationManager =
        (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(1, builder.build());
  }
  public void showNotification(Notification.Builder notificationBuilder) {
    Intent resultIntent = new Intent(this, this.getClass());

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(this.getClass());
    stackBuilder.addNextIntent(resultIntent);

    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    notificationBuilder.setContentIntent(resultPendingIntent);
    NotificationManager notificationManager =
        getSystemService(Context.NOTIFICATION_SERVICE, NotificationManager.class);

    notificationManager.notify(notificationID++, notificationBuilder.build());
  }
示例#19
0
  /**
   * Big Text Style Notification
   *
   * @return Notification
   * @see CreateNotification
   */
  private Notification setBigTextStyleNotification() {
    Bitmap remote_picture = null;

    // Create the style object with BigTextStyle subclass.
    NotificationCompat.BigTextStyle notiStyle = new NotificationCompat.BigTextStyle();
    notiStyle.setBigContentTitle("Big Text Expanded");
    notiStyle.setSummaryText("Nice big text.");

    try {
      remote_picture = BitmapFactory.decodeStream((InputStream) new URL(sample_url).getContent());
    } catch (IOException e) {
      e.printStackTrace();
    }

    // Add the big text to the style.
    CharSequence bigText =
        "This is an example of a large string to demo how much "
            + "text you can show in a 'Big Text Style' notification.";
    notiStyle.bigText(bigText);

    // 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);

    return new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.ic_launcher)
        .setAutoCancel(true)
        .setLargeIcon(remote_picture)
        .setContentIntent(resultPendingIntent)
        .addAction(R.drawable.ic_launcher, "One", resultPendingIntent)
        .addAction(R.drawable.ic_launcher, "Two", resultPendingIntent)
        .addAction(R.drawable.ic_launcher, "Three", resultPendingIntent)
        .setContentTitle("Big Text Normal")
        .setContentText("This is an example of a Big Text Style.")
        .setStyle(notiStyle)
        .build();
  }
示例#20
0
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  private void triggerNotification(String info, String info2, Context context, Intent intent) {
    NotificationCompat.Builder mBuilder =
        (NotificationCompat.Builder)
            new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_directions_bus_black_48dp)
                .setContentTitle(context.getResources().getString(R.string.app_name))
                .setAutoCancel(true)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(info2))
                .setContentText(info)
                .setVibrate(null)
                .setSound(null)
                .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(), 0));

    // Notifications
    if (Repository.getInstance().getRingtoneNotification().equals(true)) {
      // Ton
      Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
      mBuilder.setSound(alarmSound);
    }
    if (Repository.getInstance().getVibrationNotification().equals(true)) {
      // Vibration
      mBuilder.setVibrate(new long[] {1000, 1000, 1000, 1000, 1000});
    }
    if (Repository.getInstance().getLedNotification().equals(true)) {
      // LED
      mBuilder.setLights(ContextCompat.getColor(context, R.color.ledColour), 1000, 1000);
    }

    // Creates an explicit intent for an Activity
    Intent resultIntent = new Intent(context, MainActivity.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
    // application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);

    NotificationManager mNotificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(418, mBuilder.build());
  }
示例#21
0
  /**
   * Inbox Style Notification
   *
   * @return Notification
   * @see CreateNotification
   */
  private Notification setInboxStyleNotification() {
    Bitmap remote_picture = null;

    // Create the style object with InboxStyle subclass.
    NotificationCompat.InboxStyle notiStyle = new NotificationCompat.InboxStyle();
    notiStyle.setBigContentTitle("Inbox Style Expanded");

    // Add the multiple lines to the style.
    // This is strictly for providing an example of multiple lines.
    for (int i = 0; i < 5; i++) {
      notiStyle.addLine("(" + i + " of 6) Line one here.");
    }
    notiStyle.setSummaryText("+2 more Line Samples");

    try {
      remote_picture = BitmapFactory.decodeStream((InputStream) new URL(sample_url).getContent());
    } catch (IOException e) {
      e.printStackTrace();
    }

    // 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);

    return new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.ic_launcher)
        .setAutoCancel(true)
        .setLargeIcon(remote_picture)
        .setContentIntent(resultPendingIntent)
        .addAction(R.drawable.ic_launcher, "One", resultPendingIntent)
        .addAction(R.drawable.ic_launcher, "Two", resultPendingIntent)
        .addAction(R.drawable.ic_launcher, "Three", resultPendingIntent)
        .setContentTitle("Inbox Style Normal")
        .setContentText("This is an example of a Inbox Style.")
        .setStyle(notiStyle)
        .build();
  }
  @Override
  public void onCreate() {
    IntentFilter filterUsbDetached = new IntentFilter(UsbManager.ACTION_USB_DEVICE_DETACHED);
    registerReceiver(mUsbDetachedReceiver, filterUsbDetached);

    Intent settingsIntent = new Intent(this, SteeringWheelInterfaceActivity.class);
    settingsIntent.setAction(Intent.ACTION_EDIT);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(SteeringWheelInterfaceActivity.class);
    stackBuilder.addNextIntent(settingsIntent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    mNoticeBuilder.setContentIntent(resultPendingIntent);
    mNoticeBuilder.setSmallIcon(R.drawable.ic_notice);
    mNoticeBuilder.setContentTitle(getString(R.string.app_name));
    mNoticeBuilder.setContentText(getString(R.string.msg_app_starting));

    mNoticeManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNoticeManager.notify(mNoticeID, mNoticeBuilder.build());

    mCarInterface = new ElmInterface(getApplicationContext());
    mCarInterface.deviceOpenEvent_AddListener(mDeviceOpenListener);

    SharedPreferences settings =
        PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

    String baudDefault = getString(R.string.scantool_baud);
    int baudValue = Integer.parseInt(settings.getString("scantool_baud", baudDefault));
    mCarInterface.setBaudRate(baudValue);

    String deviceNumDefault = getString(R.string.scantool_device_number);
    int deviceNumValue =
        Integer.parseInt(settings.getString("scantool_device_number", deviceNumDefault));
    mCarInterface.setDeviceNumber(deviceNumValue);

    String protocolCommandDefault = getString(R.string.scantool_protocol);
    String protocolCommandValue = settings.getString("scantool_protocol", protocolCommandDefault);
    mCarInterface.setProtocolCommand(protocolCommandValue);

    String monitorCommandDefault = getString(R.string.scantool_monitor_command);
    String monitorCommandValue =
        settings.getString("scantool_monitor_command", monitorCommandDefault);
    mCarInterface.setMonitorCommand(monitorCommandValue);
  }
 @SuppressLint("NewApi")
 public static void notifyUser(String title, String text, Intent intent, Activity activity) {
   NotificationCompat.Builder mBuilder =
       new NotificationCompat.Builder(activity)
           .setSmallIcon(R.drawable.ic_launcher)
           .setContentTitle(title)
           .setContentText(text);
   TaskStackBuilder stackBuilder = TaskStackBuilder.create(activity);
   stackBuilder.addParentStack(activity.getClass());
   stackBuilder.addNextIntent(intent);
   PendingIntent resultPendingIntent =
       stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
   mBuilder.setContentIntent(resultPendingIntent);
   NotificationManager mNotificationManager =
       (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);
   // mId allows you to update the notification later on.
   mNotificationManager.notify(mId, mBuilder.build());
 }
示例#24
0
  // NOTIFICATION!
  public void startNotification() {
    String titlee = "Hey Good Looking";
    String contente = "Whats cooking?";

    File f = getBaseContext().getFileStreamPath("Done.txt");
    if (!f.exists()) return;

    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.icon)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon))
            .setContentTitle(titlee)
            .setContentText(contente)
            .setAutoCancel(true)
            .setVibrate(new long[100])
            .setPriority(Notification.PRIORITY_MAX);

    if (Build.VERSION.SDK_INT >= 21) mBuilder.setVibrate(new long[0]);

    Intent resultIntent = new Intent(this, OpenCamera.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    mBuilder.addAction(0, "Take a Selfie!", resultPendingIntent);
    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    mNotificationManager.notify(0, mBuilder.build());

    try {
      FileOutputStream fos = openFileOutput("Done.txt", Context.MODE_APPEND);
      fos.write(("yio").getBytes());
      fos.close();
    } catch (Exception e) {
    }
  }
示例#25
0
  public void sendAlert(String stockSymbol, String targetPrice, String stockState) {
    Notification.Builder mBuilder =
        new Notification.Builder(this)
            .setSmallIcon(R.drawable.appicon)
            .setContentTitle("EZQuote - '" + stockSymbol + "'")
            .setContentText(stockState + " Target Price " + targetPrice + " reached. Hurry!");
    // Creates an explicit intent for an Activity in your app

    Intent resultIntent = new Intent(this, MarketSummaryActivity.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(MarketSummaryActivity.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(getRandomNumber(), mBuilder.build());

    // Delete the alarm after it goes off.
    for (ParseObject o : alertObjs) {
      if (stockSymbol.equalsIgnoreCase((o.getString("symbol")))
          && targetPrice.equals(o.getString("targetPrice"))
          && stockState.equals(o.getString("StockState"))) {

        o.deleteInBackground();
      }
    }
  }
示例#26
0
  /**
   * Normal Notification
   *
   * @return Notification
   * @see CreateNotification
   */
  private Notification setNormalNotification() {
    Bitmap remote_picture = null;

    try {
      remote_picture = BitmapFactory.decodeStream((InputStream) new URL(sample_url).getContent());
    } catch (IOException e) {
      e.printStackTrace();
    }

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

    // TaskStackBuilder 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);

    return new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.ic_launcher)
        .setAutoCancel(true)
        .setLargeIcon(remote_picture)
        .setContentIntent(resultPendingIntent)
        .addAction(R.drawable.ic_launcher, "One", resultPendingIntent)
        .addAction(R.drawable.ic_launcher, "Two", resultPendingIntent)
        .addAction(R.drawable.ic_launcher, "Three", resultPendingIntent)
        .setContentTitle("Normal Notification")
        .setContentText("This is an example of a Normal Style.")
        .build();
  }
示例#27
0
 private static PendingIntent getPendingIntent(Context context, Intent intent, int id) {
   TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
   stackBuilder.addParentStack(intent.getComponent());
   stackBuilder.addNextIntent(intent);
   return stackBuilder.getPendingIntent(id, PendingIntent.FLAG_UPDATE_CURRENT);
 }