Example #1
0
  public static void postIModNotification(Context context) {
    NotificationManagerCompat nm = NotificationManagerCompat.from(context);
    if (!MLPreferences.getPrefsApps(context)
        .getBoolean(Common.SHOW_IMOD_RESET_NOTIFICATION, false)) {
      nm.cancel(IMOD_NOTIFICATION_ID);
      return;
    }
    Intent notifyIntent = new Intent(context, ActionActivity.class);
    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    notifyIntent.putExtra(ActionsHelper.ACTION_EXTRA_KEY, R.id.radio_imod_reset);

    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(context)
            .setContentTitle(context.getString(R.string.action_imod_reset))
            .setContentText("")
            .setSmallIcon(R.drawable.ic_apps_24dp)
            .setContentIntent(
                PendingIntent.getActivity(
                    context.getApplicationContext(),
                    0,
                    notifyIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT))
            .setOngoing(true)
            .setAutoCancel(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
      builder.setShowWhen(false);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      builder
          .setPriority(NotificationCompat.PRIORITY_MIN)
          .setCategory(NotificationCompat.CATEGORY_STATUS)
          .setColor(ContextCompat.getColor(context, R.color.accent));
    }
    nm.notify(IMOD_NOTIFICATION_ID, builder.build());
  }
  public void buildNotification() {
    int notificationId = 2;

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

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

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

    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    // Build the notification and issues it with notification manager.
    notificationManager.notify(notificationId, notificationBuilder.build());
    Log.v(TAG, "Twitter Notification Build Completed");
  }
Example #3
0
 public static void createBigNotification(
     Context context,
     Intent intent,
     String contentTitle,
     String contentText,
     List<String> lista,
     int id) {
   //        PendingIntent pendingIntent = getPendingIntent(context, intent, id);
   PendingIntent pendingIntent =
       PendingIntent.getActivity(
           context,
           0,
           new Intent(context, TodoListActivity.class),
           PendingIntent.FLAG_UPDATE_CURRENT);
   int size = lista.size();
   NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
   inboxStyle.setBigContentTitle(contentTitle);
   for (String s : lista) {
     inboxStyle.addLine(s);
   }
   inboxStyle.setSummaryText(contentText);
   NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
   builder.setDefaults(Notification.DEFAULT_ALL);
   builder.setSmallIcon(R.mipmap.ic_launcher);
   builder.setContentTitle(contentTitle);
   builder.setContentText(contentText);
   builder.setContentIntent(pendingIntent);
   builder.setAutoCancel(true);
   builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
   builder.setNumber(size);
   builder.setStyle(inboxStyle);
   NotificationManagerCompat nm = NotificationManagerCompat.from(context);
   nm.notify(id, builder.build());
 }
  /**
   * Overridden onReceive method.
   *
   * @param context: context object
   * @param intent: Intent containing start time and title
   */
  @Override
  public void onReceive(Context context, Intent intent) {
    startHour = intent.getIntExtra("hour", 0);
    startMinute = intent.getIntExtra("min", 0);
    eventTitle = intent.getStringExtra("title");
    mContext = context;

    NotificationManagerCompat manager = NotificationManagerCompat.from(context);
    manager.notify(0, createReminderNotif());
  }
  private static void showNotification(Context context) {
    NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_notification_black_24dp)
            .setContent(SjtekWidget.getWidget(context, false))
            .setPriority(NotificationCompat.PRIORITY_MIN)
            .setColor(ContextCompat.getColor(context, R.color.colorPrimary))
            .setOngoing(true);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
    notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
  }
Example #6
0
  public static void postAppInstalledNotification(Context context, String packageName) {
    Intent neverShowAgain = new Intent(MAXLOCK_ACTION_NEVER_SHOW_AGAIN);
    neverShowAgain.setClass(context, NewAppInstalledBroadcastReceiver.class);
    Intent lockApp = new Intent(MAXLOCK_ACTION_LOCK_APP);
    lockApp.setClass(context, NewAppInstalledBroadcastReceiver.class);
    lockApp.putExtra(EXTRA_PACKAGE_NAME, packageName);

    String appName;
    try {
      appName =
          context
              .getPackageManager()
              .getApplicationInfo(packageName, 0)
              .loadLabel(context.getPackageManager())
              .toString();
    } catch (PackageManager.NameNotFoundException e) {
      appName = packageName;
    }

    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(context)
            .setContentTitle(context.getString(R.string.notification_lock_new_app_title))
            .setContentText(appName)
            .setSmallIcon(R.drawable.ic_lock_48dp)
            .setAutoCancel(true)
            .addAction(
                new NotificationCompat.Action(
                    0,
                    context.getString(R.string.notification_lock_new_app_action_never_again),
                    PendingIntent.getBroadcast(
                        context, 0, neverShowAgain, PendingIntent.FLAG_UPDATE_CURRENT)))
            .addAction(
                new NotificationCompat.Action(
                    0,
                    context.getString(R.string.notification_lock_new_app_action_lock),
                    PendingIntent.getBroadcast(
                        context, 0, lockApp, PendingIntent.FLAG_UPDATE_CURRENT)));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      builder
          .setPriority(NotificationCompat.PRIORITY_HIGH)
          .setCategory(NotificationCompat.CATEGORY_RECOMMENDATION)
          .setColor(ContextCompat.getColor(context, R.color.accent));
      try {
        builder.setVibrate(new long[0]);
      } catch (SecurityException e) {
        e.printStackTrace();
      }
    }
    NotificationManagerCompat nm = NotificationManagerCompat.from(context);
    nm.notify(APP_INSTALLED_NOTIFICATION_ID, builder.build());
  }
Example #7
0
 public static void create(
     Context context, Intent intent, String contentTitle, String contentText, int id) {
   PendingIntent pendingIntent = getPendingIntent(context, intent, id);
   NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
   builder.setDefaults(Notification.DEFAULT_ALL);
   builder.setSmallIcon(R.mipmap.ic_launcher);
   builder.setContentTitle(contentTitle);
   builder.setContentText(contentText);
   builder.setContentIntent(pendingIntent);
   builder.setAutoCancel(true);
   builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
   NotificationManagerCompat nm = NotificationManagerCompat.from(context);
   nm.notify(id, builder.build());
 }
Example #8
0
 public static void creatHeadsUpNotification(
     Context context, Intent intent, String contentTitle, String contentText, int id) {
   PendingIntent pendingIntent = getPendingIntent(context, intent, id);
   NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
   builder.setDefaults(Notification.DEFAULT_ALL);
   builder.setSmallIcon(R.mipmap.ic_launcher);
   builder.setContentTitle(contentTitle);
   builder.setContentText(contentText);
   builder.setContentIntent(pendingIntent);
   builder.setAutoCancel(true);
   builder.setColor(Color.BLUE);
   builder.setFullScreenIntent(pendingIntent, false);
   NotificationManagerCompat nm = NotificationManagerCompat.from(context);
   nm.notify(id, builder.build());
 }
 @Override
 public boolean onStartJob(JobParameters params) {
   context = this;
   notificationManagerCompat = NotificationManagerCompat.from(context);
   preferences = PreferenceManager.getDefaultSharedPreferences(context);
   if (!preferences.getBoolean(AutoCleanSettingsActivity.PREF_AUTO_CLEAN, false)) return false;
   sendNotification();
   cleanUp();
   sendBroadcast(
       new Intent(
           Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
           Uri.parse("file://" + Environment.getExternalStorageDirectory())));
   new Handler()
       .postDelayed(
           new Runnable() {
             @Override
             public void run() {
               Log.v(MyUtil.PACKAGE_NAME, getString(R.string.toast_auto_clean, deletedFileCount));
               Toast.makeText(
                       context,
                       getString(R.string.toast_auto_clean, deletedFileCount),
                       Toast.LENGTH_SHORT)
                   .show();
               notificationManagerCompat.cancel(NOTIFICATION_JOB_ID);
             }
           },
           3000);
   return true;
 }
Example #10
0
  private void updateRule(Rule rule, String network, boolean blocked) {
    SharedPreferences prefs = context.getSharedPreferences(network, Context.MODE_PRIVATE);

    if ("wifi".equals(network)) {
      rule.wifi_blocked = blocked;
      if (rule.wifi_blocked == rule.wifi_default) {
        Log.i(TAG, "Removing " + rule.info.packageName + " " + network);
        prefs.edit().remove(rule.info.packageName).apply();
      } else {
        Log.i(TAG, "Setting " + rule.info.packageName + " " + network + "=" + blocked);
        prefs.edit().putBoolean(rule.info.packageName, blocked).apply();
      }
    }

    if ("other".equals(network)) {
      rule.other_blocked = blocked;
      if (rule.other_blocked == rule.other_default) {
        Log.i(TAG, "Removing " + rule.info.packageName + " " + network);
        prefs.edit().remove(rule.info.packageName).apply();
      } else {
        Log.i(TAG, "Setting " + rule.info.packageName + " " + network + "=" + blocked);
        prefs.edit().putBoolean(rule.info.packageName, blocked).apply();
      }
    }

    NotificationManagerCompat.from(context).cancel(rule.info.applicationInfo.uid);
  }
  public static void processFromActivity(Activity inActivity, Intent inIntent) {
    if (inIntent.getBooleanExtra(
        "action_button",
        false)) // Pressed an action button, need to clear the notification manually
    NotificationManagerCompat.from(inActivity).cancel(inIntent.getIntExtra("notificationId", 0));

    processIntent(inActivity, inIntent);
  }
  /** Post the sample notification(s) using current options. */
  private void postNotifications() {
    sendBroadcast(
        new Intent(NotificationIntentReceiver.ACTION_ENABLE_MESSAGES)
            .setClass(this, NotificationIntentReceiver.class));

    NotificationPreset preset =
        NotificationPresets.PRESETS[mPresetSpinner.getSelectedItemPosition()];
    CharSequence titlePreset = mTitleEditText.getText();
    CharSequence textPreset = mTextEditText.getText();
    PriorityPreset priorityPreset =
        PriorityPresets.PRESETS[mPrioritySpinner.getSelectedItemPosition()];
    ActionsPreset actionsPreset = ActionsPresets.PRESETS[mActionsSpinner.getSelectedItemPosition()];
    if (preset.actionsRequired() && actionsPreset == ActionsPresets.NO_ACTIONS_PRESET) {
      // If actions are required, but the no-actions preset was selected, change presets.
      actionsPreset = ActionsPresets.SINGLE_ACTION_PRESET;
      mActionsSpinner.setSelection(
          Arrays.asList(ActionsPresets.PRESETS).indexOf(actionsPreset), true);
    }
    NotificationPreset.BuildOptions options =
        new NotificationPreset.BuildOptions(
            titlePreset,
            textPreset,
            priorityPreset,
            actionsPreset,
            mIncludeLargeIconCheckbox.isChecked(),
            mLocalOnlyCheckbox.isChecked(),
            mIncludeContentIntentCheckbox.isChecked(),
            mVibrateCheckbox.isChecked(),
            mBackgroundPickers.getRes());
    Notification[] notifications = preset.buildNotifications(this, options);

    // Post new notifications
    for (int i = 0; i < notifications.length; i++) {
      NotificationManagerCompat.from(this).notify(i, notifications[i]);
    }
    // Cancel any that are beyond the current count.
    for (int i = notifications.length; i < postedNotificationCount; i++) {
      NotificationManagerCompat.from(this).cancel(i);
    }
    postedNotificationCount = notifications.length;
  }
 private void sendNotification() {
   NotificationCompat.Builder perBuildNotification =
       new NotificationCompat.Builder(context)
           .setOngoing(true)
           .setAutoCancel(false)
           .setContentTitle(getString(R.string.title_activity_auto_clean))
           .setContentText("")
           .setProgress(0, 0, true)
           .setColor(getResources().getColor(R.color.accent))
           .setSmallIcon(R.drawable.ic_notification_delete);
   notificationManagerCompat.notify(NOTIFICATION_JOB_ID, perBuildNotification.build());
 }
 @Override
 public void onSensorChanged(SensorEvent event) {
   proxText1.setText(String.valueOf(event.values[0]));
   if (event.values[0] > 5.0) {
     proxText.setText("STOPPED, CHANGING DIRECTION");
     Notification notification =
         new NotificationCompat.Builder(getApplication())
             .setSmallIcon(R.drawable.ic_launcher)
             .setContentTitle("ROBO STATUS:")
             .setContentText("STOPPED")
             .extend(new NotificationCompat.WearableExtender().setHintShowBackgroundOnly(true))
             .build();
     NotificationManagerCompat notificationManager =
         NotificationManagerCompat.from(getApplication());
     int notificationId = 1;
     notificationManager.notify(notificationId, notification);
   } else {
     proxText.setText("MOVING");
     Notification notification =
         new NotificationCompat.Builder(getApplication())
             .setSmallIcon(R.drawable.ic_launcher)
             .setContentTitle("ROBO STATUS:")
             .setContentText("MOVING")
             .extend(new NotificationCompat.WearableExtender().setHintShowBackgroundOnly(true))
             .build();
     NotificationManagerCompat notificationManager =
         NotificationManagerCompat.from(getApplication());
     int notificationId = 1;
     notificationManager.notify(notificationId, notification);
   }
 }
  /**
   * Create a notification
   *
   * @param context The application context
   * @param title Notification title
   * @param content Notification content.
   */
  public static void createNotification(
      final Context context, final String title, final String content, int id) {
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(context)
            .setContentTitle(title)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(content))
            .setColor(ContextCompat.getColor(context, R.color.main_theme))
            .extend(new NotificationCompat.WearableExtender().setHintShowBackgroundOnly(true))
            .setContentText(content)
            .setAutoCancel(true)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(), 0))
            .setSmallIcon(R.drawable.ic_stat_kuas_ap);

    builder.setVibrate(vibrationPattern);
    builder.setLights(Color.GREEN, 800, 800);
    builder.setDefaults(Notification.DEFAULT_SOUND);

    notificationManager.notify(id, builder.build());
  }
Example #16
0
  @Override
  public void onCreate() {
    super.onCreate();
    Logger.debug(TAG, ">>>" + "onCreate");
    audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
    notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext());

    audioFocusHelper = new AudioFocusHelper(getApplicationContext(), musicFocusable);
    componentName = new ComponentName(this, MusicIntentReceiver.class);

    wifiLock =
        ((WifiManager) getSystemService(WIFI_SERVICE))
            .createWifiLock(WifiManager.WIFI_MODE_FULL, "myLock");
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle extras = getIntent().getExtras();

    enableBackNav();

    if (extras != null) {
      ArrayList<String> ids = extras.getStringArrayList(Const.OBJECT_ID);
      int notificationID = extras.getInt(Const.NOTIFICATION_ID);
      PetListFragment petListFragment = PetListFragment.newInstance(ids);

      if (notificationID != 0) {
        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
        notificationManager.cancel(notificationID);
      }

      addFragmentToContainer(petListFragment, "PetsFragment");
    } else {
      finish();
    }
  }
  private void sendNotification(String title, String content) {

    // this intent will open the activity when the user taps the "open" action on the notification
    Intent viewIntent = new Intent(this, MyActivity.class);
    PendingIntent pendingViewIntent = PendingIntent.getActivity(this, 0, viewIntent, 0);

    // this intent will be sent when the user swipes the notification to dismiss it
    Intent dismissIntent = new Intent(Constants.ACTION_DISMISS);
    PendingIntent pendingDeleteIntent =
        PendingIntent.getService(this, 0, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(title)
            .setContentText(content)
            .setDeleteIntent(pendingDeleteIntent)
            .setContentIntent(pendingViewIntent);

    Notification notification = builder.build();

    NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
    notificationManagerCompat.notify(notificationId++, notification);
  }
 private void updateListenerMap()
 {
   Object localObject1 = NotificationManagerCompat.getEnabledListenerPackages(mContext);
   if (((Set)localObject1).equals(mCachedEnabledPackages));
   while (true)
   {
     return;
     mCachedEnabledPackages = ((Set)localObject1);
     Object localObject2 = mContext.getPackageManager().queryIntentServices(new Intent().setAction("android.support.BIND_NOTIFICATION_SIDE_CHANNEL"), 4);
     HashSet localHashSet = new HashSet();
     localObject2 = ((List)localObject2).iterator();
     while (((Iterator)localObject2).hasNext())
     {
       ResolveInfo localResolveInfo = (ResolveInfo)((Iterator)localObject2).next();
       if (((Set)localObject1).contains(localResolveInfo.serviceInfo.packageName))
       {
         ComponentName localComponentName = new ComponentName(localResolveInfo.serviceInfo.packageName, localResolveInfo.serviceInfo.name);
         if (localResolveInfo.serviceInfo.permission != null)
           Log.w("NotifManCompat", "Permission present on component " + localComponentName + ", not adding listener record.");
         else
           localHashSet.add(localComponentName);
       }
     }
     localObject1 = localHashSet.iterator();
     while (((Iterator)localObject1).hasNext())
     {
       localObject2 = (ComponentName)((Iterator)localObject1).next();
       if (!mRecordMap.containsKey(localObject2))
       {
         if (Log.isLoggable("NotifManCompat", 3))
           Log.d("NotifManCompat", "Adding listener record for " + localObject2);
         mRecordMap.put(localObject2, new ListenerRecord((ComponentName)localObject2));
       }
     }
     localObject1 = mRecordMap.entrySet().iterator();
     while (((Iterator)localObject1).hasNext())
     {
       localObject2 = (Map.Entry)((Iterator)localObject1).next();
       if (!localHashSet.contains(((Map.Entry)localObject2).getKey()))
       {
         if (Log.isLoggable("NotifManCompat", 3))
           Log.d("NotifManCompat", "Removing listener record for " + ((Map.Entry)localObject2).getKey());
         ensureServiceUnbound((ListenerRecord)((Map.Entry)localObject2).getValue());
         ((Iterator)localObject1).remove();
       }
     }
   }
 }
Example #20
0
  private void showDisabledNotification() {
    Intent main = new Intent(this, ActivityMain.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder notification =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_error_white_24dp)
            .setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_revoked))
            .setContentIntent(pi)
            .setCategory(Notification.CATEGORY_STATUS)
            .setVisibility(Notification.VISIBILITY_SECRET)
            .setColor(ContextCompat.getColor(this, R.color.colorAccent))
            .setAutoCancel(true);

    NotificationManagerCompat.from(this).notify(NOTIFY_DISABLED, notification.build());
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals("b5.project.medibro.receivers.AlarmReceiver")) {
      Toast.makeText(context, "I'm running", Toast.LENGTH_SHORT).show();
      Log.d("Alarm Receiver", "Alarm is invoked. ");

      NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
      builder.setSmallIcon(R.drawable.pill);
      builder.setContentTitle("Time to take your medicine");
      String medName = intent.getStringExtra("MedName");
      String text = "Medicine name: " + medName;
      builder.setContentText(text);

      Notification notification = builder.build();
      NotificationManagerCompat.from(context).notify(0, notification);
      Toast.makeText(context, "I'm running", Toast.LENGTH_SHORT).show();
    }
  }
 @Override
 public void didReceivedNotification(int id, Object... args) {
   if (id == NotificationCenter.FileUploadProgressChanged) {
     String fileName = (String) args[0];
     if (path != null && path.equals(fileName)) {
       Float progress = (Float) args[1];
       Boolean enc = (Boolean) args[2];
       currentProgress = (int) (progress * 100);
       builder.setProgress(100, currentProgress, currentProgress == 0);
       NotificationManagerCompat.from(ApplicationLoader.applicationContext)
           .notify(4, builder.build());
     }
   } else if (id == NotificationCenter.stopEncodingService) {
     String filepath = (String) args[0];
     if (filepath == null || filepath.equals(path)) {
       stopSelf();
     }
   }
 }
Example #23
0
  private void showDisabledNotification() {
    Intent main = new Intent(this, ActivityMain.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorAccent, tv, true);
    NotificationCompat.Builder notification =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_error_white_24dp)
            .setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_revoked))
            .setContentIntent(pi)
            .setCategory(Notification.CATEGORY_STATUS)
            .setVisibility(Notification.VISIBILITY_SECRET)
            .setColor(tv.data)
            .setOngoing(false)
            .setAutoCancel(true);

    NotificationManagerCompat.from(this).notify(NOTIFY_DISABLED, notification.build());
  }
  /** Begin to re-post the sample notification(s). */
  private void updateNotifications(boolean cancelExisting) {
    // Disable messages to skip notification deleted messages during cancel.
    sendBroadcast(
        new Intent(NotificationIntentReceiver.ACTION_DISABLE_MESSAGES)
            .setClass(this, NotificationIntentReceiver.class));

    if (cancelExisting) {
      // Cancel all existing notifications to trigger fresh-posting behavior: For example,
      // switching from HIGH to LOW priority does not cause a reordering in Notification Shade.
      NotificationManagerCompat.from(this).cancelAll();
      postedNotificationCount = 0;

      // Post the updated notifications on a delay to avoid a cancel+post race condition
      // with notification manager.
      mHandler.removeMessages(MSG_POST_NOTIFICATIONS);
      mHandler.sendEmptyMessageDelayed(MSG_POST_NOTIFICATIONS, POST_NOTIFICATIONS_DELAY_MS);
    } else {
      postNotifications();
    }
  }
Example #25
0
 private void updateNotification(MusicItem musicItem) {
   Logger.debug(TAG, ">>>" + "updateNotification:" + musicItem);
   if (musicItem == null) {
     return;
   }
   Intent intent = new Intent(getApplicationContext(), ScrollingActivity.class);
   intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
   PendingIntent pi =
       PendingIntent.getActivity(
           getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
   Notification builder =
       new NotificationCompat.Builder(getApplicationContext())
           .setContentText(musicItem.text)
           .setOngoing(false)
           .setContentIntent(pi)
           .setTicker(musicItem.text)
           .setContentTitle("Daily Practice!")
           .setSmallIcon(R.mipmap.ic_launcher)
           .build();
   notificationManagerCompat.notify(12, builder);
 }
 public int onStartCommand(Intent intent, int flags, int startId) {
   path = intent.getStringExtra("path");
   if (path == null) {
     stopSelf();
     return Service.START_NOT_STICKY;
   }
   FileLog.e("tmessages", "start video service");
   if (builder == null) {
     builder = new NotificationCompat.Builder(ApplicationLoader.applicationContext);
     builder.setSmallIcon(android.R.drawable.stat_sys_upload);
     builder.setWhen(System.currentTimeMillis());
     builder.setContentTitle(LocaleController.getString("AppName", R.string.AppName));
     builder.setTicker(LocaleController.getString("SendingVideo", R.string.SendingVideo));
     builder.setContentText(LocaleController.getString("SendingVideo", R.string.SendingVideo));
   }
   currentProgress = 0;
   builder.setProgress(100, currentProgress, currentProgress == 0);
   startForeground(4, builder.build());
   NotificationManagerCompat.from(ApplicationLoader.applicationContext).notify(4, builder.build());
   return Service.START_NOT_STICKY;
 }
Example #27
0
 private void removeDisabledNotification() {
   NotificationManagerCompat.from(this).cancel(NOTIFY_DISABLED);
 }
Example #28
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_steprecording);

    // 手錶
    String fromwear = getIntent().getStringExtra("reply");
    if (fromwear == null) {
      Bundle remoteInput = RemoteInput.getResultsFromIntent(getIntent());
      if (remoteInput != null) {
        fromwear = remoteInput.getCharSequence(Steprecording.EXTRA_VOICE_REPLY).toString();
        Log.d("fromwear", fromwear);
        wearcontent = fromwear.split(" ");
        TAG_FROM_WEAR = true;
      }
    }

    TextView ss = (TextView) findViewById(R.id.textView6);
    Intent intent = this.getIntent();
    Bundle bundle = intent.getExtras(); // 取得Bundle

    /*//是否來過
    if(intent.hasExtra("TAG_BACK_TO_RECORDING")){
        TAG_BACK_TO_RECORDING = true;
        Log.d("抓3","backtorecording");
    }*/

    TAG_CASE_NUMBER = bundle.getString("TAG_CASE_NUMBER");
    TAG_STEP_NUMBER = bundle.getString("TAG_STEP_NUMBER");
    TAG_STEP_ORDER = bundle.getInt("TAG_STEP_ORDER");

    Log.d("StepRecording", TAG_STEP_NUMBER);
    //        TAG_CASE_NUMBER = "15";
    //        TAG_STEP_NUMBER = "10";
    //        TAG_STEP_ORDER = 1;
    ss.setText(Integer.toString(TAG_STEP_ORDER));

    // 是否來過
    DatabaseHelper mDBACK = DatabaseHelper.getHelper(this);
    case_recordDao mcase_recordDao = new case_recordDao();
    List<case_recordVo> listBACK = null;
    listBACK =
        mcase_recordDao.selectRaw(
            mDBACK, "Case_number=" + TAG_CASE_NUMBER + " and Step_order=" + TAG_STEP_ORDER);
    if (listBACK.size() != 0) {
      TAG_BACK_TO_RECORDING = true;
    }

    // Hashmap for ListView
    productsList = new ArrayList<HashMap<String, String>>();
    // Loading products in Background Thread
    // new LoadInput().execute();

    // SELECT record_order,record_text FROM step_record WHERE step_number='"+Stepnumber+"'"
    DatabaseHelper mDatabaseHelper = DatabaseHelper.getHelper(this);
    mstep_recordDao = new step_recordDao();
    List<step_recordVo> list = null;
    list = mstep_recordDao.selectRaw(mDatabaseHelper, "Step_number =\"" + TAG_STEP_NUMBER + "\"");

    //  Log.d("抓", list.get(0).getRecord_order());
    //  Log.d("抓2", list.get(0).getRecord_text());

    count = list.size();
    LinearLayout ly = (LinearLayout) findViewById(R.id.linearlayoutinput);
    for (int i = 0; i < count; i++) {
      TextView text1 = new TextView(Steprecording.this);
      text1.setText(list.get(i).getRecord_text() + "(" + list.get(i).getRecord_unit() + ")");
      // 1數字2文字
      if (Integer.valueOf(list.get(i).getRecord_type()) == 1) {
        text1.setText(
            text1.getText()
                + "("
                + list.get(i).getRecord_min()
                + "~"
                + list.get(i).getRecord_max()
                + ")");
      }

      edit1[i] = new EditText(Steprecording.this.getApplicationContext());
      edit1[i].setTextColor(Color.rgb(0, 0, 0));
      edit1[i].setOnFocusChangeListener(new MyOnFocusChangeListener());
      edit1[i].setSingleLine(true);
      edit1[i].setBackgroundColor(Color.parseColor("#FDDCB9")); // #FEFBE6黃
      if (TAG_FROM_WEAR) {
        if (i < wearcontent.length) {
          edit1[i].setText(wearcontent[i]);
        }
      }
      // edit1[0].setText("eee");
      ly.addView(text1);
      ly.addView(edit1[i]);
    }

    goright = (ImageButton) findViewById(R.id.imageButton);
    goleft = (ImageButton) findViewById(R.id.imageButton2);

    detector = new GestureDetector(new MySimpleOnGestureListener());

    ScrollView sv = (ScrollView) findViewById(R.id.scrollView);
    sv.setOnTouchListener(new MyOnTouchListener());
    // LinearLayout llb = (LinearLayout)findViewById(R.id.linearLayoutbackground);
    // llb.setOnTouchListener(new MyOnTouchListener());

    messageList = new ArrayList<>();

    // 手錶
    if (!TAG_BACK_TO_RECORDING) {
      String replyLabel = getResources().getString(R.string.reply_label);
      RemoteInput remoteInput =
          new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel(replyLabel).build();
      // Create an intent for the reply action
      Intent replyIntent = new Intent(this, Steprecording.class);
      Bundle wb = new Bundle();
      wb.putString("TAG_CASE_NUMBER", TAG_CASE_NUMBER);
      wb.putString("TAG_STEP_NUMBER", TAG_STEP_NUMBER);
      wb.putInt("TAG_STEP_ORDER", TAG_STEP_ORDER);
      replyIntent.putExtras(wb);
      // replyIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
      PendingIntent replyPendingIntent =
          PendingIntent.getActivity(this, 0, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT);

      NotificationCompat.Action action =
          new NotificationCompat.Action.Builder(
                  R.drawable.cast_ic_notification_0,
                  getString(R.string.reply_label),
                  replyPendingIntent)
              .addRemoteInput(remoteInput)
              .build();

      // Create builder for the main notification
      NotificationCompat.Builder notificationBuilder =
          new NotificationCompat.Builder(this)
              .setSmallIcon(R.mipmap.ic_launcher)
              .setContentTitle("Step" + Integer.toString(TAG_STEP_ORDER))
              .setContentText("紀錄項(請往左滑):");

      /*        // Create a big text style for the second page
              NotificationCompat.BigTextStyle secondPageStyle = new NotificationCompat.BigTextStyle();
              secondPageStyle.setBigContentTitle("Page 2")
                      .bigText("A lot of text...");

              // Create second page notification
              Notification secondPageNotification =
                      new NotificationCompat.Builder(this)
                              .setStyle(secondPageStyle)
                              .build();
      */
      List extras = new ArrayList();
      for (int i = 0; i < count; i++) {

        NotificationCompat.BigTextStyle extraPageStyle = new NotificationCompat.BigTextStyle();
        extraPageStyle
            .setBigContentTitle("第" + String.valueOf(i) + "項")
            .bigText(list.get(i).getRecord_text());
        Notification extraPageNotification =
            new NotificationCompat.Builder(this).setStyle(extraPageStyle).build();
        extras.add(extraPageNotification);
      }
      /*      //如果要跳頁
              Intent mainIntent = new Intent(this, MyDisplayActivity.class);
              PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0,
                      mainIntent, PendingIntent.FLAG_CANCEL_CURRENT);
      */

      // Extend the notification builder with the second page
      Notification notification =
          notificationBuilder
              .extend(new NotificationCompat.WearableExtender().addPages(extras).addAction(action))
              // .addPage(secondPageNotification))
              // .addAction(android.R.drawable.ic_media_play, "Speak", mainPendingIntent)
              .build();

      // Issue the notification
      NotificationManagerCompat notificationManager =
          NotificationManagerCompat.from(getApplication());
      Random random = new Random();
      int notificationId = random.nextInt(9999 - 1000) + 1000;
      notificationManager.notify(notificationId, notification);

      /*        mGoogleApiClient = new GoogleApiClient.Builder(this)
              .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                  @Override
                  public void onConnected(Bundle connectionHint) {
                      Log.d(TAG, "onConnected: " + connectionHint);
                  }
                  @Override
                  public void onConnectionSuspended(int cause) {
                      Log.d(TAG, "onConnectionSuspended: " + cause);
                  }
              })
              .addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
                  @Override
                  public void onConnectionFailed(ConnectionResult result) {
                      Log.d(TAG, "onConnectionFailed: " + result);
                  }
              })
              .addApi(Wearable.API)
              .build();
      mGoogleApiClient.connect();
      sendNotification();*/
    }
  }
Example #29
0
 private void stopStats() {
   Log.i(TAG, "Stats stop");
   stats = false;
   mServiceHandler.removeMessages(MSG_STATS_UPDATE);
   NotificationManagerCompat.from(SinkholeService.this).cancel(NOTIFY_TRAFFIC);
 }
Example #30
0
    private void updateStats() {
      RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.traffic);
      SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SinkholeService.this);
      long frequency = Long.parseLong(prefs.getString("stats_frequency", "1000"));
      long samples = Long.parseLong(prefs.getString("stats_samples", "90"));
      float base = Long.parseLong(prefs.getString("stats_base", "5")) * 1000f;

      // Schedule next update
      mServiceHandler.sendEmptyMessageDelayed(MSG_STATS_UPDATE, frequency);

      long ct = SystemClock.elapsedRealtime();

      // Cleanup
      while (gt.size() > 0 && ct - gt.get(0) > samples * 1000) {
        gt.remove(0);
        gtx.remove(0);
        grx.remove(0);
      }

      // Calculate network speed
      float txsec = 0;
      float rxsec = 0;
      long ctx = TrafficStats.getTotalTxBytes();
      long rtx = TrafficStats.getTotalRxBytes();
      if (t > 0 && tx > 0 && rx > 0) {
        float dt = (ct - t) / 1000f;
        txsec = (ctx - tx) / dt;
        rxsec = (rtx - rx) / dt;
        gt.add(ct);
        gtx.add(txsec);
        grx.add(rxsec);
      }

      // Calculate application speeds
      if (prefs.getBoolean("show_top", false)) {
        if (app.size() == 0)
          for (ApplicationInfo ainfo : getPackageManager().getInstalledApplications(0))
            app.put(
                ainfo,
                TrafficStats.getUidTxBytes(ainfo.uid) + TrafficStats.getUidRxBytes(ainfo.uid));
        else if (t > 0) {
          TreeMap<Float, ApplicationInfo> mapSpeed =
              new TreeMap<>(
                  new Comparator<Float>() {
                    @Override
                    public int compare(Float value, Float other) {
                      return -value.compareTo(other);
                    }
                  });
          float dt = (ct - t) / 1000f;
          for (ApplicationInfo aInfo : app.keySet()) {
            long bytes =
                TrafficStats.getUidTxBytes(aInfo.uid) + TrafficStats.getUidRxBytes(aInfo.uid);
            float speed = (bytes - app.get(aInfo)) / dt;
            if (speed > 0) {
              mapSpeed.put(speed, aInfo);
              app.put(aInfo, bytes);
            }
          }

          StringBuilder sb = new StringBuilder();
          int i = 0;
          for (float s : mapSpeed.keySet()) {
            if (i++ >= 3) break;
            if (s < 1000 * 1000) sb.append(getString(R.string.msg_kbsec, s / 1000));
            else sb.append(getString(R.string.msg_mbsec, s / 1000 / 1000));
            sb.append(' ');
            sb.append(getPackageManager().getApplicationLabel(mapSpeed.get(s)).toString());
            sb.append("\r\n");
          }
          if (sb.length() > 0) sb.setLength(sb.length() - 2);
          remoteViews.setTextViewText(R.id.tvTop, sb.toString());
        }
      }

      t = ct;
      tx = ctx;
      rx = rtx;

      // Create bitmap
      int height = Util.dips2pixels(96, SinkholeService.this);
      int width = Util.dips2pixels(96 * 5, SinkholeService.this);
      Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

      // Create canvas
      Canvas canvas = new Canvas(bitmap);
      canvas.drawColor(Color.TRANSPARENT);

      // Determine max
      long xmax = 0;
      float ymax = base * 1.5f;
      for (int i = 0; i < gt.size(); i++) {
        long t = gt.get(i);
        float tx = gtx.get(i);
        float rx = grx.get(i);
        if (t > xmax) xmax = t;
        if (tx > ymax) ymax = tx;
        if (rx > ymax) ymax = rx;
      }

      // Build paths
      Path ptx = new Path();
      Path prx = new Path();
      for (int i = 0; i < gtx.size(); i++) {
        float x = width - width * (xmax - gt.get(i)) / 1000f / samples;
        float ytx = height - height * gtx.get(i) / ymax;
        float yrx = height - height * grx.get(i) / ymax;
        if (i == 0) {
          ptx.moveTo(x, ytx);
          prx.moveTo(x, yrx);
        } else {
          ptx.lineTo(x, ytx);
          prx.lineTo(x, yrx);
        }
      }

      // Build paint
      Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
      paint.setStyle(Paint.Style.STROKE);

      // Draw base line
      paint.setStrokeWidth(Util.dips2pixels(1, SinkholeService.this));
      paint.setColor(Color.GRAY);
      float y = height - height * base / ymax;
      canvas.drawLine(0, y, width, y, paint);

      // Draw paths
      paint.setStrokeWidth(Util.dips2pixels(2, SinkholeService.this));
      paint.setColor(ContextCompat.getColor(SinkholeService.this, R.color.colorSend));
      canvas.drawPath(ptx, paint);
      paint.setColor(ContextCompat.getColor(SinkholeService.this, R.color.colorReceive));
      canvas.drawPath(prx, paint);

      // Update remote view
      remoteViews.setImageViewBitmap(R.id.ivTraffic, bitmap);
      if (txsec < 1000 * 1000)
        remoteViews.setTextViewText(R.id.tvTx, getString(R.string.msg_kbsec, txsec / 1000));
      else
        remoteViews.setTextViewText(R.id.tvTx, getString(R.string.msg_mbsec, txsec / 1000 / 1000));

      if (rxsec < 1000 * 1000)
        remoteViews.setTextViewText(R.id.tvRx, getString(R.string.msg_kbsec, rxsec / 1000));
      else
        remoteViews.setTextViewText(R.id.tvRx, getString(R.string.msg_mbsec, rxsec / 1000 / 1000));

      // Show notification
      Intent main = new Intent(SinkholeService.this, ActivityMain.class);
      PendingIntent pi =
          PendingIntent.getActivity(
              SinkholeService.this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);

      TypedValue tv = new TypedValue();
      getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
      NotificationCompat.Builder builder =
          new NotificationCompat.Builder(SinkholeService.this)
              .setSmallIcon(R.drawable.ic_equalizer_white_24dp)
              .setContent(remoteViews)
              .setContentIntent(pi)
              .setCategory(Notification.CATEGORY_STATUS)
              .setVisibility(Notification.VISIBILITY_PUBLIC)
              .setPriority(Notification.PRIORITY_DEFAULT)
              .setColor(tv.data)
              .setOngoing(true)
              .setAutoCancel(false);
      NotificationManagerCompat.from(SinkholeService.this).notify(NOTIFY_TRAFFIC, builder.build());
    }