Exemplo n.º 1
0
  private void showNotification() {
    mBuilder =
        (NotificationCompat.Builder)
            new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_stat_action_alarm_on)
                .setContentTitle("Time Left")
                .setContentText(formatMilliseconds(secondLeft));
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, MainActivity.class);
    resultIntent.putExtra(TIME_LEFT, secondLeft);

    // 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());
  }
Exemplo n.º 2
0
  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());
  }
Exemplo n.º 3
0
  public void displayNotification(
      String msg, String msg2, int mID) // msg is big msg, msg2 is lower underneath
      {

    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.notification_icon)
            .setContentTitle(msg)
            .setContentText(msg2);
    // long[] vib = {0,200};
    // mBuilder.setVibrate(vib); // does NOT WORK
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, DisplayMessageActivity.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(DisplayMessageActivity.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());
    // ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(1000);
  }
Exemplo n.º 4
0
  @Override
  public void onEvent(EMNotifierEvent event) {
    switch (event.getEvent()) {
      case EventNewMessage:
        {
          EMMessage message = (EMMessage) event.getData();
          String userId = null;
          userId = message.getFrom();

          NotificationCompat.Builder mBuilder =
              new NotificationCompat.Builder(this)
                  .setSmallIcon(getApplicationContext().getApplicationInfo().icon)
                  .setWhen(System.currentTimeMillis())
                  .setContentTitle("有新消息了!")
                  .setContentText("A+")
                  .setAutoCancel(true);
          Intent resultIntent = new Intent(this, ChatActivity.class);
          resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
          resultIntent.putExtra("notification", true);
          resultIntent.putExtra("easemobId", userId);
          TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
          stackBuilder.addParentStack(ChatActivity.class);
          stackBuilder.addNextIntent(resultIntent);
          PendingIntent resultPendingIntent =
              stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
          mBuilder.setContentIntent(resultPendingIntent);
          NotificationManager mNotificationManager =
              (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

          mNotificationManager.notify(0, mBuilder.build());
        }
    }
  }
Exemplo n.º 5
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);
    }
  public static void showNotification(Context context) {

    //  NotificationCompat.Builder mBuilder

    Notification.Builder mBuilder =
        new Notification.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle("GPS HACK")
            .setOngoing(true)
            .setContentText("Active");

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, Home.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(Home.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);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(mId, mBuilder.build());
  }
Exemplo n.º 7
0
  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());
  }
Exemplo n.º 8
0
  private Notification getNotification() {
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.launcher_icon)
            .setContentTitle("SleepMinder is active")
            .setContentText("Sleep well :)");

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

    mBuilder.setProgress(0, 0, true);
    mBuilder.setCategory(NotificationCompat.CATEGORY_PROGRESS);

    mBuilder.setOngoing(true);

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

    mBuilder.addAction(R.drawable.ic_action_stop, "Stop tracking", stopTrackingIntent);

    return mBuilder.build();
  }
Exemplo n.º 9
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());
  }
  /**
   * The '@JavascriptInterface is required to make the method accessible from the Javascript layer
   *
   * <p>The code in this method is based on the documentation here:
   *
   * <p>http://developer.android.com/training/notify-user/build-notification.html
   *
   * @param message The message displayed in the notification
   */
  @JavascriptInterface
  public void showNotification(String message) {
    Log.wtf(TAG, "showNotification");
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(mContext)
            .setSmallIcon(R.drawable.notification_icon)
            .setContentTitle(mContext.getString(R.string.notification_title))
            .setContentText(message)
            .setAutoCancel(true);

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(mContext, MainActivity.class);
    resultIntent.putExtra(MainFragment.EXTRA_FROM_NOTIFICATION, 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
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
    // 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) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(-1, mBuilder.build());
  }
  @Override
  public Notification createNotification(String title, String content, int icon) {

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);

    notificationBuilder.setContentTitle(title);
    notificationBuilder.setContentText(content);

    notificationBuilder.setSmallIcon(icon);

    notificationBuilder.setAutoCancel(true);

    Intent resultIntent = NotificationDetailsActivity.getStartIntent(context, title, content);

    // 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(NotificationDetailsActivity.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);
    notificationBuilder.setContentIntent(resultPendingIntent);

    return notificationBuilder.build();
  }
  public boolean onSupportNavigateUp() {
    Intent upIntent = getSupportParentActivityIntent();

    if (upIntent != null) {
      if (supportShouldUpRecreateTask(upIntent)) {
        TaskStackBuilder b = TaskStackBuilder.create(this);
        onCreateSupportNavigateUpTaskStack(b);
        onPrepareSupportNavigateUpTaskStack(b);
        b.startActivities();

        try {
          ActivityCompat.finishAffinity(this);
        } catch (IllegalStateException e) {
          // This can only happen on 4.1+, when we don't have a parent or a result set.
          // In that case we should just finish().
          finish();
        }
      } else {
        // This activity is part of the application's task, so simply
        // navigate up to the hierarchical parent activity.
        supportNavigateUpTo(upIntent);
      }
      return true;
    }
    return false;
  }
Exemplo n.º 13
0
  public void setIntent(Intent intent) {
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addNextIntent(intent);

    PendingIntent pendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);
  }
Exemplo n.º 14
0
 private void createBackStack(Intent intent) {
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
     TaskStackBuilder builder = TaskStackBuilder.create(this);
     builder.addNextIntentWithParentStack(intent);
     builder.startActivities();
   } else {
     startActivity(intent);
     finish();
   }
 }
Exemplo n.º 15
0
  public void setActivity(Class activity) {
    Intent intent = new Intent(context, activity);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(activity);
    stackBuilder.addNextIntent(intent);

    PendingIntent pendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);
  }
Exemplo n.º 16
0
  private NotificationCompat.Builder buildNotification(int notif_id) {
    Builder builder = new NotificationCompat.Builder(this).setWhen(System.currentTimeMillis());
    // The default notification send the user to the waiting list
    Intent intentContent = new Intent(this, WaitListActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(WaitListActivity.class);
    stackBuilder.addNextIntent(intentContent);
    PendingIntent pendingContent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingContent);

    switch (notif_id) {
      case NOTIFICATION_SEND:
        builder
            .setSmallIcon(android.R.drawable.stat_sys_upload)
            .setTicker(getString(R.string.txt_sending))
            .setContentTitle(getString(R.string.txt_sending));
        return builder;
      case NOTIFICATION_SEND_LATER:
        builder
            .setAutoCancel(true)
            .setSmallIcon(android.R.drawable.stat_notify_error)
            .setTicker(getString(R.string.txt_error_no_connection))
            .setContentTitle(getString(R.string.txt_error_no_connection))
            .setContentText(getString(R.string.txt_error_try_again));
        return builder;
      case NOTIFICATION_ERROR:
        builder
            .setAutoCancel(true)
            .setSmallIcon(android.R.drawable.stat_notify_error)
            .setTicker(getString(R.string.txt_error_sending))
            .setContentTitle(getString(R.string.txt_error_sending))
            .setContentText(getString(R.string.txt_error_try_again));
        return builder;
      case NOTIFICATION_NEED_AUTHORIZE:
        // When authorization is need, send the user to authorization
        // process
        intentContent.setClass(this, MainActivity.class);
        intentContent.setAction(Utils.ACTION_AUTHENTICATE);
        intentContent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingAuthorize =
            PendingIntent.getActivity(this, 0, intentContent, PendingIntent.FLAG_CANCEL_CURRENT);
        builder
            .setContentIntent(pendingAuthorize)
            .setAutoCancel(true)
            .setSmallIcon(android.R.drawable.stat_notify_error)
            .setTicker(getString(R.string.txt_error_sending))
            .setContentTitle(getString(R.string.txt_error_sending))
            .setContentText(getString(R.string.txt_need_authorize));
        return builder;

      default:
        return null;
    }
  }
  private PendingIntent buildNotificationIntent() {
    Intent intent = new Intent(App.mApp, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(App.NOTIFICATION_ID, mId);
    intent.setData(Uri.parse("ClemetineDownload" + mId));

    // Create a TaskStack, so the app navigates correctly backwards
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(App.mApp);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(intent);
    return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
  }
Exemplo n.º 18
0
  public static void notify(
      String title,
      String text,
      String bigText,
      Boolean autoCancel,
      int id,
      String accountKey,
      long postId,
      Context context) {
    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(context)
            .setTicker(text)
            .setSmallIcon(R.drawable.notification_default)
            .setAutoCancel(autoCancel)
            .setWhen(System.currentTimeMillis())
            .setContentTitle(title)
            .setContentText(text)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(bigText));

    Uri ringtone = AppSettings.get().getRingtoneUri();
    if (ringtone != null) {
      builder.setSound(ringtone);
    }

    Intent resultIntent = new Intent(context, HomeActivity.class);
    resultIntent.putExtra("account_key", accountKey);
    resultIntent.putExtra("post_id", postId);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(HomeActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    int requestCode = (int) (Math.random() * Integer.MAX_VALUE);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(requestCode, PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(resultPendingIntent);

    Intent deleteIntent = new Intent(context, DeleteNotificationsReceiver.class);
    deleteIntent.putExtra("account_key", accountKey);
    deleteIntent.putExtra("post_id", postId);
    requestCode = (int) (Math.random() * Integer.MAX_VALUE);
    PendingIntent deletePendingIntent =
        PendingIntent.getBroadcast(context, requestCode, deleteIntent, 0);

    builder.setDeleteIntent(deletePendingIntent);

    saveLastNotificationDisplayed(context, accountKey, postId);

    NotificationManager notificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(id, builder.build());
  }
Exemplo n.º 19
0
 public static boolean navigateUp(@NonNull final Activity activity) {
   // first check if there is a parent declared in the manifest
   Intent upIntent = NavUtils.getParentActivityIntent(activity);
   // if there is no parent, and if this was not a new task, then just go back to simulate going to
   // a parent
   if (upIntent == null && !activity.isTaskRoot()) {
     activity.finish();
     return true;
   }
   // use the main activity, if there was no back stack and no manifest based parent
   if (upIntent == null) {
     upIntent = new Intent(CgeoApplication.getInstance(), MainActivity.class);
   }
   if (NavUtils.shouldUpRecreateTask(activity, upIntent) || activity.isTaskRoot()) {
     // This activity is NOT part of this app's task, so create a new task
     // when navigating up, with a synthesized back stack.
     TaskStackBuilder.create(activity)
         // Add all of this activity's parents to the back stack
         .addNextIntentWithParentStack(upIntent)
         // Navigate up to the closest parent
         .startActivities();
   } else {
     // This activity is part of this app's task, so simply
     // navigate up to the logical parent activity.
     NavUtils.navigateUpTo(activity, upIntent);
   }
   return true;
 }
Exemplo n.º 20
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        /* This is called when the Home (Up) button is pressed
         * in the Action Bar. http://goo.gl/lJxjA */
        Intent upIntent = new Intent(this, MainActivity.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
          TaskStackBuilder.from(this).addNextIntent(upIntent).startActivities();
          finish();
        } else {
          NavUtils.navigateUpTo(this, upIntent);
        }
        return true;

      case R.id.menu_preferences:
        Intent preferencesActivity = new Intent(getBaseContext(), SettingsActivity.class);
        startActivity(preferencesActivity);
        return true;

      case R.id.menu_upload:
        if (Constants.PRO_VERSION) {
          Intent localPhotosActivity = new Intent(getBaseContext(), LocalPhotosActivity.class);
          startActivity(localPhotosActivity);
        } else {
          BuyProDialog.show(this);
        }
        return true;

      case R.id.menu_about:
        new AboutDialogFragment().show(getSupportFragmentManager(), "AboutDialogFragment");
        return true;
    }
    return super.onOptionsItemSelected(item);
  }
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

    // Perform this loop procedure for each App Widget that belongs to this provider
    for (int appWidgetId : appWidgetIds) {
      RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_detail);

      // Create an Intent to launch MainActivity
      Intent intent = new Intent(context, MainActivity.class);
      PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
      views.setOnClickPendingIntent(R.id.widget, pendingIntent);

      // Set up the collection
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        setRemoteAdapter(context, views);
      } else {
        setRemoteAdapterV11(context, views);
      }

      // when click the Widget
      boolean useDetailActivity = context.getResources().getBoolean(R.bool.use_detail_activity);
      Intent clickIntentTemplate =
          useDetailActivity
              ? new Intent(context, MainActivity.class)
              : new Intent(context, MainActivity.class);
      PendingIntent clickPendingIntentTemplate =
          TaskStackBuilder.create(context)
              .addNextIntentWithParentStack(clickIntentTemplate)
              .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
      views.setPendingIntentTemplate(R.id.widget_list, clickPendingIntentTemplate);
      views.setEmptyView(R.id.widget_list, R.id.widget_empty);

      // Tell the AppWidgetManager to perform an update on the current app widget
      appWidgetManager.updateAppWidget(appWidgetId, views);
    }
  }
Exemplo n.º 22
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case android.R.id.home:
       // This is called when the Home (Up) button is pressed in the action bar.
       // Create a simple intent that starts the hierarchical parent activity and
       // use NavUtils in the Support Package to ensure proper handling of Up.
       Intent upIntent = new Intent(this, MainActivity.class);
       if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
         // This activity is not part of the application's task, so create a new task
         // with a synthesized back stack.
         TaskStackBuilder.from(this)
             // If there are ancestor activities, they should be added here.
             .addNextIntent(upIntent)
             .startActivities();
         finish();
       } else {
         // This activity is part of the application's task, so simply
         // navigate up to the hierarchical parent activity.
         NavUtils.navigateUpTo(this, upIntent);
       }
       return true;
   }
   return super.onOptionsItemSelected(item);
 }
Exemplo n.º 23
0
  private Notification notificacion() {
    NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(this);

    nBuilder.setSmallIcon(R.drawable.ic_launcher);
    nBuilder.setContentTitle("App Services");
    nBuilder.setContentText("Servicio Iniciado");

    Intent intent = new Intent(this, MenuPrincipal.class);

    TaskStackBuilder tStack = TaskStackBuilder.create(this);
    tStack.addNextIntent(intent);

    PendingIntent pIntent = tStack.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    nBuilder.setContentIntent(pIntent);

    return nBuilder.build();
  }
 protected void onHomePressed() {
   Intent upIntent = NavUtils.getParentActivityIntent(this);
   if (upIntent != null && NavUtils.shouldUpRecreateTask(this, upIntent)) {
     TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
   } else {
     finish();
   }
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TaskStackBuilder builder = TaskStackBuilder.create(this);
    Intent proxyIntent = getIntent();
    if (!proxyIntent.hasExtra(EXTRA_INTENTS)) {
      finish();
      return;
    }

    for (Parcelable parcelable : proxyIntent.getParcelableArrayExtra(EXTRA_INTENTS)) {
      builder.addNextIntent((Intent) parcelable);
    }

    builder.startActivities();
    finish();
  }
  // override the onPushOpen() method to open "ViewBloodRequestActivity" instead of app's launcher
  // activity when user taps on a Notification
  @Override
  protected void onPushOpen(Context context, Intent intent) {

    // since we override onPushOpen() method, we need to track our app's push open event manually
    ParseAnalytics.trackAppOpenedInBackground(intent);

    String targetActivity = null;

    // get the value of key "target" from the JSON data received in Parse Push notification
    try {
      JSONObject pushData = getJSONDataFromIntent(intent);
      targetActivity = pushData.getString("target");
    } catch (JSONException e) {
      Log.e(TAG, "Unexpected JSONException when receiving push data: ", e);
    }

    // get the launcher activity class for the app from ParsePushBroadcastReceiver's getActivity()
    // method
    Class<? extends Activity> cls = getActivity(context, intent);

    Intent activityIntent;
    if (targetActivity != null && !targetActivity.isEmpty()) {
      // send an explicit intent to open ViewBloodRequestActivity on tapping a push notification
      activityIntent = new Intent(context, ViewBloodRequestActivity.class);
      Log.d("notttt - ", "entering if");
    } else {
      // open the launcher activity of the app
      activityIntent = new Intent(context, cls);
      Log.d("notttt - ", "entering else");
    }

    if (Build.VERSION.SDK_INT >= 16) {
      TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
      stackBuilder.addParentStack(cls);
      stackBuilder.addNextIntent(activityIntent);
      stackBuilder.startActivities();
    } else {
      activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      activityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      context.startActivity(activityIntent);
    }
  }
  /**
   * Hace visibles las notificaciones
   *
   * @param mensajes Mensajes a notificar
   */
  public void mostrarNotificacion(LinkedList<Mensaje> mensajes) {

    String textoNotificacionAuxiliar = "";
    for (int i = 0; i < mensajes.size(); i++) {
      textoNotificacionAuxiliar +=
          mensajes.get(i).getUsuario() + ": " + mensajes.get(i).getMensaje() + "\n";
    }

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

    if (mensajes.size() == 0) {
      mNotificationManager.cancel(mId);
      return;
    }

    if ((textoNotificacion.compareTo(textoNotificacionAuxiliar) == 0)) {
      return;
    }

    textoNotificacion = textoNotificacionAuxiliar;

    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.not)
            .setContentTitle(getString(R.string.nuevos_mensajes))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(textoNotificacion));
    // .setSound(alarmSound);
    mBuilder.setSound(alarmSound);

    Intent resultIntent = new Intent(this, ListaDeConversacionesActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(ListaDeConversacionesActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(mId, mBuilder.build());
  }
Exemplo n.º 28
0
  private void setOnClickPendingIntent(Context context, RemoteViews views) {
    Intent intent = new Intent(context, ResultsActivity.class);
    intent.putExtra(Shared.Child.EXTRA_IS_STARTED_FROM_WIDGET, true);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingIntent =
        TaskStackBuilder.create(context)
            .addNextIntentWithParentStack(intent)
            .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    views.setOnClickPendingIntent(R.id.widget, pendingIntent);
  }
  /**
   * Posts a notification in the notification bar when a transition is detected. If the user clicks
   * the notification, control goes to the MainActivity.
   */
  private void sendNotification(String notificationDetails) {
    // Create an explicit content Intent that starts the main Activity.
    Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);

    // Construct a task stack.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    // Add the main Activity to the task stack as the parent.
    stackBuilder.addParentStack(MainActivity.class);

    // Push the content Intent onto the stack.
    stackBuilder.addNextIntent(notificationIntent);

    // Get a PendingIntent containing the entire back stack.
    PendingIntent notificationPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    // Get a notification builder that's compatible with platform versions >= 4
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    // Define the notification settings.
    builder
        .setSmallIcon(R.drawable.ic_launcher)
        // In a real app, you may want to use a library like Volley
        // to decode the Bitmap.
        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
        .setColor(Color.RED)
        .setContentTitle(notificationDetails)
        .setContentText(getString(R.string.geofence_transition_notification_text))
        .setContentIntent(notificationPendingIntent);

    // Dismiss notification once the user touches it.
    builder.setAutoCancel(true);

    // Get an instance of the Notification manager
    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    // Issue the notification
    mNotificationManager.notify(0, builder.build());
  }
Exemplo n.º 30
0
  public static void notify(Context context, Intent intent, String msg) {
    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("My budly!")
            .setContentText(msg);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    if (intent != null) {
      stackBuilder.addNextIntent(intent);
    }
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification n = mBuilder.build();
    // n.defaults |= Notification.DEFAULT_SOUND;
    n.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
    mNotificationManager.notify(0x12345678, n);
  }