Пример #1
0
  @Override
  public void onReceive(Context context, Intent intent) {

    String action = intent.getAction();

    boolean createAlarmIntent =
        context.getString(R.string.create_alarm_intent).equals(action)
            || ACTION_BOOT_COMPLETED.equals(action);
    boolean removeAlarmIntent = context.getString(R.string.remove_alarm_intent).equals(action);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    PendingIntent birthdayNotifications =
        PendingIntent.getService(
            context,
            0,
            new Intent(context, HappyDaysService.class),
            PendingIntent.FLAG_CANCEL_CURRENT);

    if (createAlarmIntent) {
      createAlarm(alarmManager, birthdayNotifications, context);
      return;
    }

    if (removeAlarmIntent) {
      alarmManager.cancel(birthdayNotifications);
      return;
    }
  }
    /**
     * Handle incoming transaction requests. The incoming requests are initiated by the MMSC Server
     * or by the MMS Client itself.
     */
    @Override
    public void handleMessage(Message msg) {
      int serviceId = msg.arg1;
      Intent intent = (Intent) msg.obj;
      if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
        Log.v(TAG, "handleMessage serviceId: " + serviceId + " intent: " + intent);
      }
      if (intent != null) {
        String action = intent.getAction();

        int error = intent.getIntExtra("errorCode", 0);

        if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) {
          Log.v(TAG, "handleMessage action: " + action + " error: " + error);
        }

        if (MESSAGE_SENT_ACTION.equals(intent.getAction())) {
          handleSmsSent(intent, error);
        } else if (SMS_RECEIVED_ACTION.equals(action)) {
          handleSmsReceived(intent, error);
        } else if (ACTION_BOOT_COMPLETED.equals(action)) {
          handleBootCompleted();
        } else if (TelephonyIntents.ACTION_SERVICE_STATE_CHANGED.equals(action)) {
          handleServiceStateChanged(intent);
        } else if (ACTION_SEND_MESSAGE.endsWith(action)) {
          handleSendMessage();
        } else if (ACTION_SEND_INACTIVE_MESSAGE.equals(action)) {
          handleSendInactiveMessage();
        }
      }
      // NOTE: We MUST not call stopSelf() directly, since we need to
      // make sure the wake lock acquired by AlertReceiver is released.
      SmsReceiver.finishStartingService(SmsReceiverService.this, serviceId);
    }
		@Override
		public void handleMessage(Message msg) {
			Log.v("TTSNotifierService", "handleMessage()");

			Intent intent = (Intent) msg.obj;
			String action = intent.getAction();

			readState();
			storeAndUpdateVolume();

			boolean cbxEnable = mPrefs.getBoolean("cbxEnable", false);
			boolean cbxObeySilentMode = mPrefs.getBoolean("cbxObeySilentMode", true);

			if (action == null) return;
			if (!cbxEnable) return;
			if (cbxObeySilentMode && silentMode) return;

			// When calling ignore other notifications
			if (!ACTION_PHONE_STATE.equals(action) && (mTelephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE))
				return;

			Log.v("TTSNotifierService", "Action: " + action);

			if (ACTION_PHONE_STATE.equals(action)) {
				handleACTION_PHONE_STATE(intent);
			} else if (ACTION_SMS_RECEIVED.equals(action)) {
				handleACTION_SMS_RECEIVED(intent);
			} else if (ACTION_BATTERY_LOW.equals(action)) {
				handleACTION_BATTERY_LOW(intent);
			} else if (ACTION_MEDIA_BAD_REMOVAL.equals(action)) {
				handleACTION_MEDIA_BAD_REMOVAL(intent);
			} else if (ACTION_BOOT_COMPLETED.equals(action)) {
				handleACTION_BOOT_COMPLETED(intent);
			} else if (ACTION_PROVIDER_CHANGED.equals(action)) {
				handleACTION_PROVIDER_CHANGED(intent);
			} else if (ACTION_MEDIA_MOUNTED.equals(action)) {
				handleACTION_MEDIA_MOUNTED(intent);
			} else if (ACTION_MEDIA_UNMOUNTED.equals(action)) {
				handleACTION_MEDIA_UNMOUNTED(intent);
			} else if (ACTION_PICK_WIFI_NETWORK.equals(action)) {
				handleACTION_PICK_WIFI_NETWORK(intent);
			} else if (ACTION_WIFI_STATE_CHANGE.equals(action)) {
				handleACTION_WIFI_STATE_CHANGE(intent);
			} else if (ACTION_SUPPLICANT_CONNECTION_CHANGE_ACTION.equals(action)) {
				handleSUPPLICANT_CONNECTION_CHANGE_ACTION(intent);
			}
			// ACTION_PHONE_STATE is different because we are using a thread in it
			if (!ACTION_PHONE_STATE.equals(action))
				restoreVolume();
		}