コード例 #1
0
  @Override
  public int onStartCommand(final Intent intent, final int flags, final int startId) {
    super.onStartCommand(intent, flags, startId);

    if (intent == null) {
      return START_STICKY;
    }

    String action = intent.getAction();
    mLogger.fine("request action: " + action);
    if (action == null) {
      return START_STICKY;
    }

    Bundle resExtra = new Bundle();

    resExtra.putInt(DConnectMessage.EXTRA_RESULT, DConnectMessage.RESULT_ERROR);
    resExtra.putInt(
        DConnectMessage.EXTRA_REQUEST_CODE,
        intent.getIntExtra(DConnectMessage.EXTRA_REQUEST_CODE, -1));
    Intent response = MessageUtils.createResponseIntent(intent.getExtras(), resExtra);
    if (BuildConfig.DEBUG) {
      response.putExtra("debug", "DevicePlugin");
    }

    if (IntentDConnectMessage.ACTION_GET.equals(action)
        || IntentDConnectMessage.ACTION_POST.equals(action)
        || IntentDConnectMessage.ACTION_PUT.equals(action)
        || IntentDConnectMessage.ACTION_DELETE.equals(action)) {
      onRequest(intent, response);
    }

    return START_STICKY;
  }
コード例 #2
0
 /**
  * 指定されたアクションがDevice Connectのアクションかチェックします.
  *
  * @param action チェックするアクション
  * @return Device Connectのアクションの場合はtrue、それ以外はfalse
  */
 private boolean checkRequestAction(String action) {
   return IntentDConnectMessage.ACTION_GET.equals(action)
       || IntentDConnectMessage.ACTION_POST.equals(action)
       || IntentDConnectMessage.ACTION_PUT.equals(action)
       || IntentDConnectMessage.ACTION_DELETE.equals(action);
 }