/**
  * Compare two {@link Intent}s.
  *
  * @param i1 first intent
  * @param i2 second intent
  * @return true if both intents describe the same command
  */
 public static boolean equals(final Intent i1, final Intent i2) {
   Bundle b1 = i1.getExtras();
   Bundle b2 = i2.getExtras();
   if (b1 == null || b2 == null) {
     return false;
   }
   b1 = b1.getBundle(EXTRAS_COMMAND);
   b2 = b2.getBundle(EXTRAS_COMMAND);
   if (b1 == null || b2 == null) {
     return false;
   }
   final short s1 = b1.getShort(TYPE);
   final short s2 = b2.getShort(TYPE);
   return s1 == s2;
 }
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    Bundle data = intent.getExtras();

    numPDUsReceived++;

    if (numPDUsReceived == 1) {
      // Add packet type + time stamp
      buffer.put((byte) 0x03); // Type
      buffer.put((byte) data.getInt("usli.smd.payload.hour")); // Hour
      buffer.put((byte) data.getInt("usli.smd.payload.minute")); // Minute
      buffer.put((byte) data.getInt("usli.smd.payload.second")); // Second
    }

    // Add data
    buffer.putDouble(data.getDouble("usli.smd.payload.latitude")); // Latitude
    buffer.putDouble(data.getDouble("usli.smd.payload.longitude")); // Longitude
    buffer.putShort(data.getShort("usli.smd.payload.pressure1")); // Pressure
    buffer.putShort(data.getShort("usli.smd.payload.temperature1")); // Temperature
    buffer.putShort(data.getShort("usli.smd.payload.humidity1")); // Humidity
    buffer.putShort(data.getShort("usli.smd.payload.solarIrradiance1")); // Solar Irradiance
    buffer.putShort(data.getShort("usli.smd.payload.uvRadiation1")); // UV Radiation

    if (numPDUsReceived == numPDUs) {
      String message = "";
      message += data.getInt("usli.smd.payload.hour");
      message += ":" + data.getInt("usli.smd.payload.minute");
      message += ":" + data.getInt("usli.smd.payload.second");
      message += ";" + data.getDouble("usli.smd.payload.latitude");
      message += "," + data.getDouble("usli.smd.payload.longitude");
      message += "," + data.getFloat("usli.smd.payload.bearing");
      message += "," + data.getInt("usli.smd.payload.signal");
      // message += "," + data.getFloat("usli.smd.payload.accelX");
      // message += "," + data.getFloat("usli.smd.payload.accelY");
      // message += "," + data.getFloat("usli.smd.payload.accelZ");
      // Send byte[] to SMSSender
      SMSDataPacket.putExtra("destination", 0);
      SMSDataPacket.putExtra("message", message);
      startService(SMSDataPacket);

      // Reset service
      numPDUsReceived = 0;
      buffer.clear();
    }

    return START_STICKY;
  }
 public void processCommand(Bundle b) {
   try {
     short com = b.getShort("command");
     byte[] args = b.getByteArray("arguments");
     int ch = b.getInt("chan");
     if (com == 106) {
       tmpch = ch;
       constructorVideo();
       start();
       // captureButton.performClick();
     } else if (com == 107) {
       stop();
       // captureButton.performClick();
     } else procCmd.process(com, args, ch);
   } catch (Exception e) {
     sendError("Error on Client:" + e.getMessage());
   }
 }
  @SmallTest
  @MediumTest
  @LargeTest
  public void testAllTypes() {
    Bundle originalBundle = new Bundle();

    putBoolean(BOOLEAN_KEY, originalBundle);
    putBooleanArray(BOOLEAN_ARRAY_KEY, originalBundle);
    putByte(BYTE_KEY, originalBundle);
    putByteArray(BYTE_ARRAY_KEY, originalBundle);
    putShort(SHORT_KEY, originalBundle);
    putShortArray(SHORT_ARRAY_KEY, originalBundle);
    putInt(INT_KEY, originalBundle);
    putIntArray(INT_ARRAY_KEY, originalBundle);
    putLong(LONG_KEY, originalBundle);
    putLongArray(LONG_ARRAY_KEY, originalBundle);
    putFloat(FLOAT_KEY, originalBundle);
    putFloatArray(FLOAT_ARRAY_KEY, originalBundle);
    putDouble(DOUBLE_KEY, originalBundle);
    putDoubleArray(DOUBLE_ARRAY_KEY, originalBundle);
    putChar(CHAR_KEY, originalBundle);
    putCharArray(CHAR_ARRAY_KEY, originalBundle);
    putString(STRING_KEY, originalBundle);
    putStringList(STRING_LIST_KEY, originalBundle);
    originalBundle.putSerializable(SERIALIZABLE_KEY, AccessTokenSource.FACEBOOK_APPLICATION_WEB);

    ensureApplicationContext();

    SharedPreferencesTokenCachingStrategy cache =
        new SharedPreferencesTokenCachingStrategy(getContext());
    cache.save(originalBundle);

    SharedPreferencesTokenCachingStrategy cache2 =
        new SharedPreferencesTokenCachingStrategy(getContext());
    Bundle cachedBundle = cache2.load();

    Assert.assertEquals(
        originalBundle.getBoolean(BOOLEAN_KEY), cachedBundle.getBoolean(BOOLEAN_KEY));
    assertArrayEquals(
        originalBundle.getBooleanArray(BOOLEAN_ARRAY_KEY),
        cachedBundle.getBooleanArray(BOOLEAN_ARRAY_KEY));
    Assert.assertEquals(originalBundle.getByte(BYTE_KEY), cachedBundle.getByte(BYTE_KEY));
    assertArrayEquals(
        originalBundle.getByteArray(BYTE_ARRAY_KEY), cachedBundle.getByteArray(BYTE_ARRAY_KEY));
    Assert.assertEquals(originalBundle.getShort(SHORT_KEY), cachedBundle.getShort(SHORT_KEY));
    assertArrayEquals(
        originalBundle.getShortArray(SHORT_ARRAY_KEY), cachedBundle.getShortArray(SHORT_ARRAY_KEY));
    Assert.assertEquals(originalBundle.getInt(INT_KEY), cachedBundle.getInt(INT_KEY));
    assertArrayEquals(
        originalBundle.getIntArray(INT_ARRAY_KEY), cachedBundle.getIntArray(INT_ARRAY_KEY));
    Assert.assertEquals(originalBundle.getLong(LONG_KEY), cachedBundle.getLong(LONG_KEY));
    assertArrayEquals(
        originalBundle.getLongArray(LONG_ARRAY_KEY), cachedBundle.getLongArray(LONG_ARRAY_KEY));
    Assert.assertEquals(originalBundle.getFloat(FLOAT_KEY), cachedBundle.getFloat(FLOAT_KEY));
    assertArrayEquals(
        originalBundle.getFloatArray(FLOAT_ARRAY_KEY), cachedBundle.getFloatArray(FLOAT_ARRAY_KEY));
    Assert.assertEquals(originalBundle.getDouble(DOUBLE_KEY), cachedBundle.getDouble(DOUBLE_KEY));
    assertArrayEquals(
        originalBundle.getDoubleArray(DOUBLE_ARRAY_KEY),
        cachedBundle.getDoubleArray(DOUBLE_ARRAY_KEY));
    Assert.assertEquals(originalBundle.getChar(CHAR_KEY), cachedBundle.getChar(CHAR_KEY));
    assertArrayEquals(
        originalBundle.getCharArray(CHAR_ARRAY_KEY), cachedBundle.getCharArray(CHAR_ARRAY_KEY));
    Assert.assertEquals(originalBundle.getString(STRING_KEY), cachedBundle.getString(STRING_KEY));
    assertListEquals(
        originalBundle.getStringArrayList(STRING_LIST_KEY),
        cachedBundle.getStringArrayList(STRING_LIST_KEY));
    Assert.assertEquals(
        originalBundle.getSerializable(SERIALIZABLE_KEY),
        cachedBundle.getSerializable(SERIALIZABLE_KEY));
  }
 /**
  * Retrieve extended data from the request.
  *
  * @param name The name of the desired item.
  * @param defaultValue the value to be returned if no value of the desired type is stored with the
  *     given name.
  * @return the value of an item that previously added with putExtra() or the default value if none
  *     was found.
  * @see #putExtra(String, short)
  */
 public short getShortExtra(String name, short defaultValue) {
   return mExtras == null ? defaultValue : mExtras.getShort(name, defaultValue);
 }