コード例 #1
0
  @Override
  public void onReceive(Context context, Intent intent) {
    final String action = intent.getAction();
    final boolean enabled = intent.getBooleanExtra(LocationManager.EXTRA_GPS_ENABLED, false);

    boolean visible;
    int iconId, textResId;

    if (action.equals(LocationManager.GPS_FIX_CHANGE_ACTION) && enabled) {
      // GPS is getting fixes
      iconId = com.android.internal.R.drawable.stat_sys_gps_on;
      textResId = R.string.gps_notification_found_text;
      visible = true;
    } else if (action.equals(LocationManager.GPS_ENABLED_CHANGE_ACTION) && !enabled) {
      // GPS is off
      visible = false;
      iconId = textResId = 0;
    } else {
      // GPS is on, but not receiving fixes
      iconId = R.drawable.stat_sys_gps_acquiring_anim;
      textResId = R.string.gps_notification_searching_text;
      visible = true;
    }

    try {
      if (visible) {
        Intent gpsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        gpsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, gpsIntent, 0);

        Notification n =
            new Notification.Builder(mContext)
                .setSmallIcon(iconId)
                .setContentTitle(mContext.getText(textResId))
                .setOngoing(true)
                .setContentIntent(pendingIntent)
                .getNotification();

        // Notification.Builder will helpfully fill these out for you no matter what you do
        n.tickerView = null;
        n.tickerText = null;

        n.priority = Notification.PRIORITY_HIGH;

        int[] idOut = new int[1];
        mNotificationService.enqueueNotificationWithTag(
            mContext.getPackageName(), null, GPS_NOTIFICATION_ID, n, idOut);
      } else {
        mNotificationService.cancelNotification(mContext.getPackageName(), GPS_NOTIFICATION_ID);
      }
    } catch (android.os.RemoteException ex) {
      // well, it was worth a shot
    }
  }
コード例 #2
0
    private void updateUsbNotification() {
      if (mNotificationManager == null || !mUseUsbNotification) return;
      int id = 0;
      Resources r = mContext.getResources();
      if (mConnected) {
        if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_MTP)) {
          id = com.android.internal.R.string.usb_mtp_notification_title;
        } else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_PTP)) {
          id = com.android.internal.R.string.usb_ptp_notification_title;
        } else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_MASS_STORAGE)) {
          id = com.android.internal.R.string.usb_cd_installer_notification_title;
        } else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ACCESSORY)) {
          id = com.android.internal.R.string.usb_accessory_notification_title;
        } else {
          // There is a different notification for USB tethering so we don't need one here
          // if (!containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_RNDIS)) {
          //    Slog.e(TAG, "No known USB function in updateUsbNotification");
          // }
        }
      }
      if (id != mUsbNotificationId) {
        // clear notification if title needs changing
        if (mUsbNotificationId != 0) {
          mNotificationManager.cancelAsUser(null, mUsbNotificationId, UserHandle.ALL);
          mUsbNotificationId = 0;
        }
        if (id != 0) {
          CharSequence message = r.getText(com.android.internal.R.string.usb_notification_message);
          CharSequence title = r.getText(id);

          Notification notification = new Notification();
          notification.icon = com.android.internal.R.drawable.stat_sys_data_usb;
          notification.when = 0;
          notification.flags = Notification.FLAG_ONGOING_EVENT;
          notification.tickerText = title;
          notification.defaults = 0; // please be quiet
          notification.sound = null;
          notification.vibrate = null;
          notification.priority = Notification.PRIORITY_MIN;

          Intent intent =
              Intent.makeRestartActivityTask(
                  new ComponentName("com.android.settings", "com.android.settings.UsbSettings"));
          PendingIntent pi =
              PendingIntent.getActivityAsUser(mContext, 0, intent, 0, null, UserHandle.CURRENT);
          notification.setLatestEventInfo(mContext, title, message, pi);
          mNotificationManager.notifyAsUser(null, id, notification, UserHandle.ALL);
          mUsbNotificationId = id;
        }
      }
    }
コード例 #3
0
 /**
  * This method can be overriden in order to create a foreground SpiceService. By default, it will
  * create a notification that can be used to set a spiceService to foreground (depending on the
  * versions of Android, the behavior is different : before ICS, no notification is shown, on ICS+,
  * a notification is shown with app icon). On Jelly Bean+, the notifiation only appears when
  * notification bar is expanded / pulled down.
  *
  * @return a notification used to tell user that the SpiceService is still running and processing
  *     requests.
  */
 @SuppressWarnings("deprecation")
 public Notification createDefaultNotification() {
   Notification notification = new Notification();
   if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH
       && android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
     notification.icon = getApplicationInfo().icon;
     // temporary fix https://github.com/octo-online/robospice/issues/200
     PendingIntent pendingIntent =
         PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0);
     notification.setLatestEventInfo(this, "", "", pendingIntent);
   } else {
     notification.icon = 0;
   }
   notification.tickerText = null;
   notification.when = System.currentTimeMillis();
   if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
     notification.priority = Notification.PRIORITY_MIN;
   }
   return notification;
 }
コード例 #4
0
ファイル: Sunday.java プロジェクト: NateshR/TaskTable
  public void Notification() {
    Calendar calendar = Calendar.getInstance();
    int day = calendar.get(Calendar.DAY_OF_WEEK);
    if (day == Calendar.SUNDAY) {
      Boolean check = someData.getBoolean("CHECK", true);

      StringBuffer buffer = new StringBuffer();
      if (values.length != 0) {
        Intent resultIntent = new Intent(this, Sunday.class);
        PendingIntent resultPendingIntent =
            PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        for (int i = 0; i < values.length; i++) {
          buffer.append(values[i]);
          buffer.append(System.getProperty("line.separator"));
        }
        convert = buffer.toString();
        cs_big = convert;
        cs_small = values[0];
        nb =
            new NotificationCompat.Builder(this)
                .setContentText(cs_small)
                .setSmallIcon(R.drawable.ic_launchernew)
                .setContentTitle("Task to do")
                .setStyle(new NotificationCompat.BigTextStyle().bigText(cs_big));

        nb.setContentIntent(resultPendingIntent);
        n = nb.build();
        n.priority = 1;
        ;
        n.flags = Notification.FLAG_ONGOING_EVENT;
        if (check) {
          nm.notify(0, n);
        } else {
          nm.cancel(0);
        }
      } else {
        nm.cancel(0);
      }
    }
  }
コード例 #5
0
    private void updateAdbNotification() {
      if (mNotificationManager == null) return;
      final int id = com.android.internal.R.string.adb_active_notification_title;
      if (mAdbEnabled && mConnected) {
        if ("0".equals(SystemProperties.get("persist.adb.notify"))
            || Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.ADB_NOTIFY, 1)
                == 0) return;

        if (!mAdbNotificationShown) {
          Resources r = mContext.getResources();
          CharSequence title = r.getText(id);
          CharSequence message =
              r.getText(com.android.internal.R.string.adb_active_notification_message);

          Notification notification = new Notification();
          notification.icon = com.android.internal.R.drawable.stat_sys_adb;
          notification.when = 0;
          notification.flags = Notification.FLAG_ONGOING_EVENT;
          notification.tickerText = title;
          notification.defaults = 0; // please be quiet
          notification.sound = null;
          notification.vibrate = null;
          notification.priority = Notification.PRIORITY_LOW;

          Intent intent =
              Intent.makeRestartActivityTask(
                  new ComponentName(
                      "com.android.settings", "com.android.settings.DevelopmentSettings"));
          PendingIntent pi =
              PendingIntent.getActivityAsUser(mContext, 0, intent, 0, null, UserHandle.CURRENT);
          notification.setLatestEventInfo(mContext, title, message, pi);
          mAdbNotificationShown = true;
          mNotificationManager.notifyAsUser(null, id, notification, UserHandle.ALL);
        }
      } else if (mAdbNotificationShown) {
        mAdbNotificationShown = false;
        mNotificationManager.cancelAsUser(null, id, UserHandle.ALL);
      }
    }