How to declare variables in Android app where it can be red by my Arduino ADK

I’m having trouble with my Android app code, where it should read an incoming message and control my Arduino Mega ADK output pin, to either Logic high or Logic LOW depending on the received message. i’m sorry, i’m new android and arduino programming. Below are my codes

Arduino Sketch

#include <Max3421e.h>
#include <Usb.h>
#include <AndroidAccessory.h>

#define COMMAND_LED 0x2
#define TARGET_PIN_2 0x2
#define VALUE_ON 0x1
#define VALUE_OFF 0x0

#define PIN 2

AndroidAccessory acc("Manufacturer",

byte rcvmsg[3];

void setup() {
pinMode(PIN, OUTPUT);

void loop() {
if (acc.isConnected()) {
//read the received data into the byte array
int len =, sizeof(rcvmsg), 1);
if (len > 0) {
if (rcvmsg[0] == COMMAND_LED) {
  if (rcvmsg[1] == TARGET_PIN_2){
      //get the switch state
      byte value = rcvmsg[2];
      //set output pin to according state
      if(value == VALUE_ON) {
        digitalWrite(PIN, HIGH);
        } else if(value == VALUE_OFF) {
          digitalWrite(PIN, LOW);

package readnewsms.adk;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.util.Log;

public class NewMessage extends BroadcastReceiver {

private static final byte COMMAND_LED = 0x2;
private static final byte TARGET_PIN_2 = 0x2;
private static final byte VALUE_ON = 0x1;
private static final byte VALUE_OFF = 0x0;

// Get the object of SmsManager
final SmsManager sms = SmsManager.getDefault();

public void onReceive(Context context, Intent intent) {

    // Retrieves a map of extended data from the intent.
    final Bundle bundle = intent.getExtras();

    try {

        if (bundle != null) {

            byte[] buffer = new byte[3];
            buffer[0] = COMMAND_LED;
            buffer[1] = TARGET_PIN_2;

            final Object[] pdusObj = (Object[]) bundle.get("pdus");

            for (int i = 0; i < pdusObj.length; i++) {

                SmsMessage currentMessage = SmsMessage.createFromPdu((byte[])     pdusObj[i]);
                String phoneNumber = currentMessage.getDisplayOriginatingAddress();

                String senderNum = phoneNumber;
                String message = currentMessage.getDisplayMessageBody();

                Log.i("SmsReceiver", "senderNum: "+ senderNum + "; message: " + message);

                if  (message.equals("High")){ buffer[2] = VALUE_ON; } 

                else {
                       buffer[2] = VALUE_OFF;


            // end for loop
          } // bundle is null 
    } catch (Exception e) {
        Log.e("SmsReceiver", "Exception smsReceiver" +e);


i placed the codes for usb communication in my, also added permissions in the manifest file. i don’t think i declared or placed those variables in the right places in my it gives no error but it won’t work.