hi i'm a new android app beginner.i was wondering if anyone could help me to solve the issue here:

public class MainActivity extends Activity  {

BluetoothAdapter adapter = null;
    BTClient _bt;
    ZephyrProtocol _protocol;
    NewConnectedListener _NConnListener;
    private final int HEART_RATE = 0x100;
    private final int INSTANT_SPEED = 0x101;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //findViewById(R.id.calculateButton).setOnClickListener(new HeartDemo());
        /*Sending a message to android that we are going to initiate a pairing request*/
        IntentFilter filter = new IntentFilter("android.bluetooth.device.action.PAIRING_REQUEST");
        /*Registering a new BTBroadcast receiver from the Main Activity context with pairing request event*/
       this.getApplicationContext().registerReceiver(new BTBroadcastReceiver(), filter);
        // Registering the BTBondReceiver in the application that the status of the receiver has changed to Paired
        IntentFilter filter2 = new IntentFilter("android.bluetooth.device.action.BOND_STATE_CHANGED");
       this.getApplicationContext().registerReceiver(new BTBondReceiver(), filter2);

     //Obtaining the handle to act on the CONNECT button
       TextView tv = (TextView) findViewById(R.id.labelStatusMsg);
        String ErrorText  = "Not Connected to HxM ! !";
         tv.setText(ErrorText);

       Button btnConnect = (Button) findViewById(R.id.ButtonConnect);
       if (btnConnect != null)
       {
        btnConnect.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                String BhMacID = "00:07:80:6D:7C:6D";
                //String BhMacID = "00:07:80:88:F6:BF";
                adapter = BluetoothAdapter.getDefaultAdapter();

                Set<BluetoothDevice> pairedDevices = adapter.getBondedDevices();

                if (pairedDevices.size() > 0) 
                {
                       for (BluetoothDevice device : pairedDevices) 
                       {
                        if (device.getName().startsWith("HXM")) 
                        {
                            BluetoothDevice btDevice = device;
                            BhMacID = btDevice.getAddress();
                               break;

                        }
                       }


                }

                //BhMacID = btDevice.getAddress();
                BluetoothDevice Device = adapter.getRemoteDevice(BhMacID);
                String DeviceName = Device.getName();
                _bt = new BTClient(adapter, BhMacID);
                _NConnListener = new NewConnectedListener(Newhandler,Newhandler);
                _bt.addConnectedEventListener(_NConnListener);

                TextView tv1 = (EditText)findViewById(R.id.labelHeartRate);
                tv1.setText("000");

                 tv1 = (EditText)findViewById(R.id.labelInstantSpeed);
                 tv1.setText("0.0");

                 //tv1 =    (EditText)findViewById(R.id.labelSkinTemp);
                 //tv1.setText("0.0");

                 //tv1 =    (EditText)findViewById(R.id.labelPosture);
                 //tv1.setText("000");

                 //tv1 =    (EditText)findViewById(R.id.labelPeakAcc);
                 //tv1.setText("0.0");
                if(_bt.IsConnected())
                {
                    _bt.start();
                    TextView tv = (TextView) findViewById(R.id.labelStatusMsg);
                    String ErrorText  = "Connected to HxM "+DeviceName;
                         tv.setText(ErrorText);

                         //Reset all the values to 0s

                }
                else
                {
                    TextView tv = (TextView) findViewById(R.id.labelStatusMsg);
                    String ErrorText  = "Unable to Connect !";
                         tv.setText(ErrorText);
                }
            }
        });
       }
       /*Obtaining the handle to act on the DISCONNECT button*/
       Button btnDisconnect = (Button) findViewById(R.id.ButtonDisconnect);
       if (btnDisconnect != null)
       {
        btnDisconnect.setOnClickListener(new OnClickListener() {
                @Override
                /*Functionality to act if the button DISCONNECT is touched*/
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    /*Reset the global variables*/
                    TextView tv = (TextView) findViewById(R.id.labelStatusMsg);
                String ErrorText  = "Disconnected from HxM!";
                     tv.setText(ErrorText);

                    /*This disconnects listener from acting on received messages*/  
                    _bt.removeConnectedEventListener(_NConnListener);
                    /*Close the communication with the device & throw an exception if failure*/
                    _bt.Close();

                }
        });
       }
   }
   private class BTBondReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            Bundle b = intent.getExtras();
            BluetoothDevice device = adapter.getRemoteDevice(b.get("android.bluetooth.device.extra.DEVICE").toString());
            Log.d("Bond state", "BOND_STATED = " + device.getBondState());
        }
   }
   private class BTBroadcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d("BTIntent", intent.getAction());
            Bundle b = intent.getExtras();
            Log.d("BTIntent", b.get("android.bluetooth.device.extra.DEVICE").toString());
            Log.d("BTIntent", b.get("android.bluetooth.device.extra.PAIRING_VARIANT").toString());
            try {
                BluetoothDevice device = adapter.getRemoteDevice(b.get("android.bluetooth.device.extra.DEVICE").toString());
                Method m = BluetoothDevice.class.getMethod("convertPinToBytes", new Class[] {String.class} );
                byte[] pin = (byte[])m.invoke(device, "1234");
                m = device.getClass().getMethod("setPin", new Class [] {pin.getClass()});
                Object result = m.invoke(device, pin);
                Log.d("BTTest", result.toString());
            } catch (SecurityException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (NoSuchMethodException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
   }

   private void HeartRate(){
        EditText firstName;
        EditText lastName;
        EditText currentAge;
        Button calculate;


        firstName = (EditText)findViewById(R.id.text2);
        lastName =(EditText)findViewById(R.id.text4);
        currentAge =(EditText)findViewById(R.id.text6);

        String cAge = currentAge.getText().toString();
        double numAge = Double.parseDouble(cAge);

        double maxRate = 220 - numAge;
        double minTargetRate = (maxRate)*(.5);
        double maxTargetRate = (maxRate)*(.5);



   }



   private void restHR(){

       int restingHR = 0;
       String statusHR;

        if(restingHR <= 56 && restingHR >= 60)
            {
                statusHR = "excellent";
            }
        else if
        (restingHR <= 56 && restingHR >= 60)
            {
                statusHR = "good";
            }
        else if
        (restingHR <= 56 && restingHR >= 60)
            {
                statusHR = "above average";
            }
        else if
        (restingHR <= 56 && restingHR >= 60)
            {
                statusHR = "average";
            }
        else if
        (restingHR <= 56 && restingHR >= 60)
            {
                statusHR = "below average";
            }
        else if
            (restingHR <= 56 && restingHR >= 60)
                {
                    statusHR = "poor";
                }

   }

   private void walkHR(){

       int walkingHR = 0;
       String statusHR;

        if(walkingHR <= 56 && walkingHR >= 60)
            {
                statusHR = "excellent";
            }
        else if
        (walkingHR <= 56 && walkingHR >= 60)
            {
                statusHR = "good";
            }
        else if
        (walkingHR <= 56 && walkingHR >= 60)
            {
                statusHR = "above average";
            }
        else if
        (walkingHR <= 56 && walkingHR >= 60)
            {
                statusHR = "average";
            }
        else if
        (walkingHR <= 56 && walkingHR >= 60)
            {
                statusHR = "below average";
            }
        else if
            (walkingHR <= 56 && walkingHR >= 60)
                {
                    statusHR = "poor";
                }

   }

   private void runHR(){

       int runningHR = 0;
       String statusHR;

        if(runningHR <= 56 && runningHR >= 60)
            {
                statusHR = "excellent";
            }
        else if
        (runningHR <= 56 && runningHR >= 60)
            {
                statusHR = "good";
            }
        else if
        (runningHR <= 56 && runningHR >= 60)
            {
                statusHR = "above average";
            }
        else if
        (runningHR <= 56 && runningHR >= 60)
            {
                statusHR = "average";
            }
        else if
        (runningHR <= 56 && runningHR >= 60)
            {
                statusHR = "below average";
            }
        else if
            (runningHR <= 56 && runningHR >= 60)
                {
                    statusHR = "poor";
                }

   }





class HeartDemo implements OnClickListener{
       public void onClick(View v){
           Intent intent = new Intent(MainActivity.this, Activity2.class);
           startActivity(intent);
       }
   }

   final  Handler Newhandler = new Handler(){
    public void handleMessage(Message msg)
    {
        TextView tv;
        switch (msg.what)
        {
        case HEART_RATE:
            String HeartRatetext = msg.getData().getString("HeartRate");
            tv = (EditText)findViewById(R.id.labelHeartRate);
            System.out.println("Heart Rate Info is "+ HeartRatetext);
            if (tv != null)tv.setText(HeartRatetext);
        break;

        case INSTANT_SPEED:
            String InstantSpeedtext = msg.getData().getString("InstantSpeed");
            tv = (EditText)findViewById(R.id.labelInstantSpeed);
            if (tv != null)tv.setText(InstantSpeedtext);

        break;

        }
    }

 };

and the next activity to show the result based on the main:

package com.example.zephyr;

import android.app.Activity;
import android.os.Bundle;

public class Activity2 extends Activity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main1);
    }
}

much help is greatly appreciated

Recommended Answers

All 2 Replies

some of the parts contains the source code...i just added in some extra code

if anyone could help me to solve the issue here

What issue? You just uploaded large chunk of code that cannot be compiled because resources are missing and you did not mentioned any errors or problems that you are having

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.