예제 #1
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());
        }
    }
  }
  @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();
  }
예제 #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);
  }
예제 #4
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());
  }
  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);
    }
  }
예제 #6
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());
  }
  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());
  }
예제 #8
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);
    }
예제 #9
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;
 }
예제 #10
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();
  }
예제 #11
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());
  }
예제 #13
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());
  }
  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;
  }
 protected void onHomePressed() {
   Intent upIntent = NavUtils.getParentActivityIntent(this);
   if (upIntent != null && NavUtils.shouldUpRecreateTask(this, upIntent)) {
     TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
   } else {
     finish();
   }
 }
예제 #16
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);
  }
  /**
   * Create and show a notification containing the conversations name where the new conversation
   * message was posted.
   */
  private void sendNewConversationMessageNotification(int groupId, int conversationId) {
    Intent intent;
    boolean loggedIn = Util.getInstance(this).getLoggedInModerator() != null;
    if (loggedIn) {
      // User is logged in as local moderator.
      intent = new Intent(this, ModeratorMainActivity.class);
    } else {
      // User isn't logged in.
      intent = new Intent(this, GroupActivity.class);
    }
    intent.putExtra("groupId", groupId);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    // Create a PendingIntent containing the entire back stack.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    if (loggedIn) {
      stackBuilder.addParentStack(ModeratorMainActivity.class);
    } else {
      stackBuilder.addParentStack(GroupActivity.class);
    }
    stackBuilder.addNextIntent(intent);
    PendingIntent pendingIntent =
        stackBuilder.getPendingIntent(groupId, PendingIntent.FLAG_UPDATE_CURRENT);

    // Set group icon as large icon.
    Conversation conversation =
        new GroupDatabaseManager(getApplicationContext()).getConversation(conversationId);
    Bitmap bitmap =
        BitmapFactory.decodeResource(
            getResources(),
            GroupController.getConversationIcon(conversation, getApplicationContext()));
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_notification_icon_1)
            .setColor(ContextCompat.getColor(this, R.color.uni_main_primary))
            .setLargeIcon(bitmap)
            .setContentTitle(
                String.format(
                    getString(R.string.push_message_conversation), conversation.getTitle()))
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    if (conversation.getNumberOfUnreadConversationMessages() > 1) {
      notificationBuilder.setContentText(
          getString(R.string.push_message_new_conversation_messages));
      notificationBuilder.setNumber(conversation.getNumberOfUnreadConversationMessages());
    } else {
      notificationBuilder.setContentText(getString(R.string.push_message_new_conversation_message));
    }

    NotificationManager notificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(5, notificationBuilder.build());
  }
예제 #18
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);
  }
예제 #19
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();
   }
 }
예제 #20
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;
    }
  }
예제 #21
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);
  }
예제 #22
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        Intent upIntent = NavUtils.getParentActivityIntent(this);
        if (upIntent != null)
          if (NavUtils.shouldUpRecreateTask(this, upIntent))
            TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
          else NavUtils.navigateUpTo(this, upIntent);

        return true;
      case R.id.menu_all:
        List<String> listRestriction = PrivacyManager.getRestrictions();

        // Get toggle
        boolean restricted = false;
        for (String restrictionName : listRestriction)
          if (PrivacyManager.getRestricted(
              null, this, mAppInfo.getUid(), restrictionName, null, false, false)) {
            restricted = true;
            break;
          }

        // Do toggle
        restricted = !restricted;
        for (String restrictionName : listRestriction)
          PrivacyManager.setRestricted(
              null, this, mAppInfo.getUid(), restrictionName, null, restricted);

        // Refresh display
        if (mPrivacyListAdapter != null) mPrivacyListAdapter.notifyDataSetChanged();

        return true;
      case R.id.menu_app_launch:
        Intent LaunchIntent =
            getPackageManager().getLaunchIntentForPackage(mAppInfo.getPackageName());
        startActivity(LaunchIntent);
        return true;
      case R.id.menu_app_settings:
        startActivity(
            new Intent(
                android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
                Uri.parse("package:" + mAppInfo.getPackageName())));
        return true;
      case R.id.menu_app_store:
        startActivity(
            new Intent(
                Intent.ACTION_VIEW, Uri.parse("market://details?id=" + mAppInfo.getPackageName())));
        return true;
      default:
        return super.onOptionsItemSelected(item);
    }
  }
  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);
  }
  /**
   * Create and show a simple notification containing the channels name where the new announcement
   * was posted.
   */
  private void sendAnnouncementNotification(int channelId) {
    ChannelDatabaseManager channelDBM = new ChannelDatabaseManager(this);
    Channel channel = channelDBM.getChannel(channelId);
    int numberOfAnnouncements = channelDBM.getNumberOfUnreadAnnouncements(channelId);

    Intent intent;
    boolean loggedIn = Util.getInstance(this).getLoggedInModerator() != null;
    if (loggedIn) {
      // User is logged in as local moderator.
      intent = new Intent(this, ModeratorChannelActivity.class);
    } else {
      // User isn't logged in.
      intent = new Intent(this, ChannelActivity.class);
    }
    intent.putExtra("channelId", channelId);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    // Create a PendingIntent containing the entire back stack.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    if (loggedIn) {
      stackBuilder.addParentStack(ModeratorChannelActivity.class);
    } else {
      stackBuilder.addParentStack(ChannelActivity.class);
    }
    stackBuilder.addNextIntent(intent);
    PendingIntent pendingIntent =
        stackBuilder.getPendingIntent(channelId, PendingIntent.FLAG_UPDATE_CURRENT);

    // Set channel icon as large icon.
    Bitmap bitmap =
        BitmapFactory.decodeResource(getResources(), ChannelController.getChannelIcon(channel));
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_notification_icon_1)
            .setColor(ContextCompat.getColor(this, R.color.uni_main_primary))
            .setLargeIcon(bitmap)
            .setContentTitle(channel.getName())
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    if (numberOfAnnouncements > 1) {
      notificationBuilder.setContentText(getString(R.string.push_message_new_announcements));
      notificationBuilder.setNumber(numberOfAnnouncements);
    } else {
      notificationBuilder.setContentText(getString(R.string.push_message_new_announcement));
    }

    NotificationManager notificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(1, notificationBuilder.build());
  }
  /*
   * Build the RemoteViews for the notification. We also need to add the appropriate "back stack"
   * so when user goes into the CastPlayerActivity, she can have a meaningful "back" experience.
   */
  private RemoteViews build(MediaInfo info, Bitmap bitmap, boolean isPlaying)
      throws CastException, TransientNetworkDisconnectionException, NoConnectionException {
    Bundle mediaWrapper = Utils.fromMediaInfo(mCastManager.getRemoteMediaInformation());
    Intent contentIntent = new Intent(this, mTargetActivity);

    contentIntent.putExtra("media", mediaWrapper);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    stackBuilder.addParentStack(mTargetActivity);

    stackBuilder.addNextIntent(contentIntent);
    if (stackBuilder.getIntentCount() > 1) {
      stackBuilder.editIntentAt(1).putExtra("media", mediaWrapper);
    }

    // Gets a PendingIntent containing the entire back stack
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(NOTIFICATION_ID, PendingIntent.FLAG_UPDATE_CURRENT);

    MediaMetadata mm = info.getMetadata();

    RemoteViews rv = new RemoteViews(getPackageName(), R.layout.custom_notification);
    if (mIsIcsOrAbove) {
      addPendingIntents(rv, isPlaying, info);
    }
    if (null != bitmap) {
      rv.setImageViewBitmap(R.id.iconView, bitmap);
    } else {
      bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.dummy_album_art);
      rv.setImageViewBitmap(R.id.iconView, bitmap);
    }
    rv.setTextViewText(R.id.titleView, mm.getString(MediaMetadata.KEY_TITLE));
    String castingTo =
        getResources().getString(R.string.casting_to_device, mCastManager.getDeviceName());
    rv.setTextViewText(R.id.subTitleView, castingTo);
    mNotification =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_action_notification)
            .setContentIntent(resultPendingIntent)
            .setContent(rv)
            .setAutoCancel(false)
            .setOngoing(true)
            .build();

    // to get around a bug in GB version, we add the following line
    // see https://code.google.com/p/android/issues/detail?id=30495
    mNotification.contentView = rv;

    return rv;
  }
예제 #26
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());
  }
  @SuppressWarnings("unchecked")
  @Override
  public boolean onMenuItemSelected(int featureId, MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        Intent upIntent = new Intent(this, SelectAccountActivity.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
          TaskStackBuilder.create(this).addNextIntent(upIntent).startActivities();
        } else {
          NavUtils.navigateUpTo(this, upIntent);
        }
        return true;

      case R.id.menu_sync_now:

        // This is a convenient way of enabling and running the contact photo
        // sync.

        Account a = new Account(account, ACCOUNT_TYPE);
        ContentResolver.setSyncAutomatically(a, CONTACT_PHOTO_AUTHORITY, true);
        ContentResolver.requestSync(a, CONTACT_PHOTO_AUTHORITY, new Bundle());
        Toast.makeText(this, getResources().getString(R.string.sync_requested), Toast.LENGTH_LONG)
            .show();
        break;

      case R.id.menu_download_all:
      case R.id.menu_upload_all:
        new DownloadUploadTask(
                item.getItemId() == R.id.menu_download_all
                    ? DownloadUploadTask.TYPE_DOWNLOAD
                    : DownloadUploadTask.TYPE_UPLOAD)
            .execute(((ContactAdapter) contactList.getAdapter()).getBackingList());

        break;

      case R.id.menu_refresh:

        // XXX This is ugly and hackish. This of course doesn't stop us from being
        // lazy and using it here.

        onPause();
        onResume();
        break;
    }
    return super.onOptionsItemSelected(item);
  }
예제 #28
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();
  }
예제 #29
0
 private void backToPictureMenu() {
   Intent upIntent = NavUtils.getParentActivityIntent(this);
   upIntent.putExtra("REDIRECT", true);
   if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
     // 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(this)
         // 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(this, upIntent);
   }
 }
  @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();
  }