As you may have guessed, you can do this with BroadcastReceiverand Service. You must configure the broadcast receiver to handle the “bluetooth disconnect” event, and then disconnect the service in order to do something.
In the manifest, declare the receiver:
<receiver android:name=".YourReceiver">
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED"/>
</intent-filter>
</receiver>
In yours BroadcastReceiveryou would do something like this:
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) {
context.startService(new Intent(context, YourService.class));
}
}
And yours Servicewill handle the creation of a dummy file:
@Override
public void onCreate() {
}
- .., . , Bluetooth, , .