Android Open Source - UbarCDC Bluetooth State Receiver






From Project

Back to project page UbarCDC.

License

The source code is released under:

Apache License

If you think the Android project UbarCDC 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.ubergrund.UbarCDC;
/*  w  w  w.j a  v  a 2 s .c  o  m*/
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

/**
 * Receives broadcaast intents from the Bluetooth subsystem
 *
 * UbarCDC
 * Copyright (C) 2013 Tim Otto
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Created with IntelliJ IDEA.
 * User: Tim
 * Date: 8/31/13
 * Time: 8:32 PM
 */
public class BluetoothStateReceiver extends BroadcastReceiver {

    private static final String TAG = "UbarCDC/BluetoothStateReceiver";

    public void onReceive(Context context, Intent intent) {
//        Log.d(TAG, "Intent {"+intent+"}");
        final BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

        final Intent serviceIntent = new Intent(context, UbarCDCService.class);
        serviceIntent.setAction(intent.getAction());
        serviceIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);

        if ("android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED".equals(intent.getAction())) {
            serviceIntent.putExtra(BluetoothProfile.EXTRA_STATE, intent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1));
            serviceIntent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, intent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, -1));
        }

        context.startService(serviceIntent);
    }
}




Java Source Code List

com.ubergrund.UbarCDC.BluetoothStateReceiver.java
com.ubergrund.UbarCDC.CDCEventReceiver.java
com.ubergrund.UbarCDC.GoogleMusicHelperService.java
com.ubergrund.UbarCDC.MenuProvider.java
com.ubergrund.UbarCDC.MusicSearchActivity.java
com.ubergrund.UbarCDC.SPPDriver.java
com.ubergrund.UbarCDC.StatusInfo.java
com.ubergrund.UbarCDC.UbarAccService.java
com.ubergrund.UbarCDC.UbarCDCService.java
com.ubergrund.UbarCDC.UbarCDC.java