Android Open Source - EnergyWastingApp Blue Tooth Burn






From Project

Back to project page EnergyWastingApp.

License

The source code is released under:

Copyright ? 2013-2014 Pekka Ekman <pekka.ekman@aalto.fi> 2013 Babujee Jerome Robin <robin.babujeejerome@aalto.fi> Permission is hereby granted, free of charge, to any person obtaining a ...

If you think the Android project EnergyWastingApp 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 fi.aalto.pekman.energywastingapp.components;
/*from  w  ww. ja v  a2 s  .co m*/
import android.bluetooth.*;
import android.content.Intent;
import android.util.Log;

public class BlueToothBurn extends Component {

  private volatile static BluetoothAdapter bluetooth = null;
  private static final int REQUEST_ENABLE_BT = 1;
  private volatile static boolean running = false;
  
  @Override
  public String getName() { 
    return "BlueToothBurn";
  }

  @Override
  public void start() {
    
    if(null == bluetooth){
      bluetooth = BluetoothAdapter.getDefaultAdapter();
      if(bluetooth != null)
      {
        if (!bluetooth.isEnabled()) {
            Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            context.startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
        } else {
          markTurnedOn();
        }
        
        if(bluetooth.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE)
        {
          Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
          discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 30);
          context.startActivity(discoverableIntent);
        }
        running = true;
        
        if(bluetooth.isEnabled()){
          Thread thread = new Thread() {
            @Override
            public void run() {
              while(running){
                try {
                  Thread.sleep(30);
                  if(bluetooth.isDiscovering()){
                    bluetooth.cancelDiscovery();
                  }
                  bluetooth.startDiscovery();
                } catch (InterruptedException e) {
                  e.printStackTrace();
                }
              }
              
              bluetooth = null;
            }
          };
          thread.start();
        }
        
      } else {
        Log.e("BlueToothBurn", "BlueTooth cannot be turned on!");
      }
    }
  }

  @Override
  public void stop() {
    running = false;
    markTurnedOff();
  }

  @Override
  public void onPause() {
    
  }

}




Java Source Code List

fi.aalto.pekman.energywastingapp.MainActivity.java
fi.aalto.pekman.energywastingapp.components.AbstractCamera.java
fi.aalto.pekman.energywastingapp.components.AbstractFileWriter.java
fi.aalto.pekman.energywastingapp.components.AppDirFileWriter.java
fi.aalto.pekman.energywastingapp.components.BlueToothBurn.java
fi.aalto.pekman.energywastingapp.components.CPUBurn.java
fi.aalto.pekman.energywastingapp.components.Component.java
fi.aalto.pekman.energywastingapp.components.Display.java
fi.aalto.pekman.energywastingapp.components.ExtStorageFileWriter.java
fi.aalto.pekman.energywastingapp.components.GPSCoordSearch.java
fi.aalto.pekman.energywastingapp.components.RecordAudio.java
fi.aalto.pekman.energywastingapp.components.StillCamera.java
fi.aalto.pekman.energywastingapp.components.TonePlay.java
fi.aalto.pekman.energywastingapp.components.Vibration.java
fi.aalto.pekman.energywastingapp.components.VideoCamera.java
fi.aalto.pekman.energywastingapp.components.WiFiDataTransfer.java