Android Open Source - AsteroidGetLocationOverBT My Receiver






From Project

Back to project page AsteroidGetLocationOverBT.

License

The source code is released under:

Apache License

If you think the Android project AsteroidGetLocationOverBT 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.freak.android.getlocation;
/* w  ww.j  a v a2s. c o m*/
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class MyReceiver extends BroadcastReceiver {
    private static final String TAG = "BT_RECEIVER";
    private static final boolean DEBUG = true;

    public MyReceiver() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        if (DEBUG)
            Log.d(TAG, "Intent received");
        int connectionState = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE, -1);
        int btState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1);

        if (connectionState == BluetoothAdapter.STATE_CONNECTED) {
            if (DEBUG)
                Log.d(TAG, "Connected to BT device");
            Intent newIntent = new Intent(context, MyService.class);
            context.startService(newIntent);
        }
        else if (connectionState == BluetoothAdapter.STATE_DISCONNECTED) {
            if (DEBUG)
                Log.d(TAG, "Disconnected from BT device");
            Intent newIntent = new Intent(context, MyService.class);
            context.stopService(newIntent);
        }
        else if (btState == BluetoothAdapter.STATE_OFF) {
            if (DEBUG)
                Log.d(TAG, "BT off");
            Intent newIntent = new Intent(context, MyService.class);
            context.stopService(newIntent);
        }

    }
}




Java Source Code List

com.freak.android.getlocation.ApplicationTest.java
com.freak.android.getlocation.MyActivity.java
com.freak.android.getlocation.MyReceiver.java
com.freak.android.getlocation.MyService.java
com.freak.android.getlocation.ReceiveThreadListener.java
com.freak.android.getlocation.ReceiveThread.java
com.freak.android.getlocation.StatisticsActivity.java
com.freak.fidji.locationoverbt.ApplicationTest.java
com.freak.fidji.locationoverbt.BtEventsReceiver.java
com.freak.fidji.locationoverbt.ManagerService.java
com.freak.fidji.locationoverbt.MyService.java
com.freak.fidji.locationoverbt.SendingThreadListener.java
com.freak.fidji.locationoverbt.SendingThread.java