Android Open Source - final_project_android Bluetooth






From Project

Back to project page final_project_android.

License

The source code is released under:

MIT License

If you think the Android project final_project_android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.geminnu.hexagon;
//from w w w .j av a  2 s .c o  m
import java.io.IOException;
import java.util.UUID;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.util.Log;

public class Bluetooth {
  
  private String TAG = "Bluetooth";
  private UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
  private String arduinoMacAdrr;
    private BluetoothSocket btSocket = null;
    private BluetoothAdapter mBluetoothAdapter = null;
    private BluetoothDevice arduino;
  
  
  public Bluetooth(String hexAddr) {
    
    this.arduinoMacAdrr = hexAddr;
    
  }
  
  public BluetoothSocket createBlueSocket() {
      
      mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
      arduino = mBluetoothAdapter.getRemoteDevice(arduinoMacAdrr);
      
      try {
        
  //      btSocket = device.createInsecureRfcommSocketToServiceRecord(MY_UUID);
        btSocket = arduino.createRfcommSocketToServiceRecord(MY_UUID);
        btSocket.connect();
        Log.d(TAG, "Bluetooth socket creation completed");
        
      } catch (IOException e1) {
        
        Log.d(TAG, "Bluetooth socket creation failed");
      }
      
      if(btSocket.isConnected()) {
        return btSocket;
      } else {
        return null;
      }
    }
    
    public void closeBlueSocket() {
      
      try {
        if(btSocket.isConnected()) {
          btSocket.close();
          Log.d(TAG, "Bluetooth socket destruction completed");
        } else {
          
        }
      } catch(IOException e2) {
        Log.d(TAG, "Bluetooth socket destruction failed");
      }
    }
    
    public boolean isAlive() {
      
      if(btSocket.isConnected()) {
        return true;
      }
      
      return false;
    }  
}




Java Source Code List

com.geminnu.hexagon.Alert.java
com.geminnu.hexagon.ArduinoMessage.java
com.geminnu.hexagon.ArduinoParser.java
com.geminnu.hexagon.ArduinoReceiver.java
com.geminnu.hexagon.ArduinoService.java
com.geminnu.hexagon.ArduinoStatusEventListener.java
com.geminnu.hexagon.ArduinoStatusEvent.java
com.geminnu.hexagon.ArduinoStatusManager.java
com.geminnu.hexagon.ArduinoStatus.java
com.geminnu.hexagon.ArduinoTask.java
com.geminnu.hexagon.ArduinoTransmitter.java
com.geminnu.hexagon.BioSensorEventListener.java
com.geminnu.hexagon.BioSensorEvent.java
com.geminnu.hexagon.BioSensorListenerItem.java
com.geminnu.hexagon.BioSensorManagerService.java
com.geminnu.hexagon.BioSensor.java
com.geminnu.hexagon.Bluetooth.java
com.geminnu.hexagon.CoordinatorActionListener.java
com.geminnu.hexagon.Coordinator.java
com.geminnu.hexagon.MainActivity.java
com.geminnu.hexagon.MessageListener.java
com.geminnu.hexagon.MessageSender.java
com.geminnu.hexagon.MySQLiteHelper.java
com.geminnu.hexagon.Profile.java
com.geminnu.hexagon.Reading.java
com.geminnu.hexagon.Wifi.java