How to get Bluetooth Connecting status in android for API-level 7?
<p>In my android project, my two devices are paired with each other. I want to send a file from one device to other device via Bluetooth and when this file is received either automatically or manually, my app on that device needs to read this file and do some action based on it. </p>

<p>I have created one service whose OnCreate method, I register one broadcast listener for CONNECTION_STATE_CHANGED. This service is started in OnCreate method of my main activity. So even if my app is not on front-end, this broadcast receiver would read the file and do the required action. First of all, is this the right way to do it? and if yes, please let me know how?</p>

<p>Following is my service file which registers a broadcast receiver. When I run this code and receive file, Broadcast Receiver's OnReceive is not being called.</p>

<pre><code>package com.android;

import android.app.Service;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class FileReceiver extends Service {

    private static final String ACTION = "android.bluetooth.adapter.action.CONNECTION_STATE_CHANGED";

//    private BroadcastReceiver   BT_CONNECTION_BCAST_Receiver;
@Override
public IBinder onBind(Intent arg0) {
    return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i("LocalService", "Received start id " + startId + ": " + intent);
    // We want this service to continue running until it is explicitly
    // stopped, so return sticky.
    return START_STICKY;
}

@Override
public void onCreate() {
    super.onCreate();

    final IntentFilter theFilter = new IntentFilter();
    theFilter.addAction(ACTION);

    Log.i("LocalService", "On created ");




    // Registers the receiver so that your service will listen for broadcasts
    this.registerReceiver(this.btReceiver_Receiver, theFilter);
}

private final BroadcastReceiver btReceiver_Receiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {
        // Do whatever you need it to do when it receives the broadcast
        // Example show a Toast message...
        String action = intent.getAction();
        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        Log.i("BT_Connection", "Inside Receiver");

        if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            Log.i("BT_Connection", "Device Found");
         }

        if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) 
        {
            Log.i("BT_Connection", "On BT Connection");

        }


        Log.i("LocalService", "On Broadcast Receiver");

        showSuccessfulBroadcast();
    }
};
@Override
public void onDestroy() {
    super.onDestroy();
    Log.i("LocalService", "On Being Destroyed!!");

    // Do not forget to unregister the receiver!!!
    this.unregisterReceiver(this.btReceiver_Receiver);
}

private void showSuccessfulBroadcast() {
    Toast.makeText(this, "Broadcast Successful!!!", Toast.LENGTH_LONG).show();
}
}
</code></pre>
