How can I limit that a file has been successfully sent via bluetooth using Android 4+

I wrote an application that sends a file to a laptop via bluetooth. I would like to be able to delete this file automatically after some confirmation that the file was sent successfully.

I receive a Toast message from BlueTooth. Share that the file has been uploaded, but how can I detect this from my application?

Is there a callback I can use to do this?

Here is my method of sending a file using Android 4+

 File filename = new File(path + "/" + itemValue);
           Uri uri = Uri.fromFile(filename);
           //send file via bluetooth
           Intent intent = new Intent(Intent.ACTION_SEND);
           //this causes us to send via bluetooth only
           intent.setClassName("", "");
           intent.putExtra(Intent.EXTRA_STREAM, uri);
           startActivity(Intent.createChooser(intent, "Send file"));



source to share

1 answer

Browsing the source, I see


that appear to indicate that the broadcast will be sent after the transfer is complete.

/** intent action used to indicate the completion of a handover transfer */
public static final String ACTION_BT_OPP_TRANSFER_DONE =



/** intent extra used to indicate the success of a handover transfer */
public static final String EXTRA_BT_OPP_TRANSFER_STATUS =

public static final int HANDOVER_TRANSFER_STATUS_SUCCESS = 0;
public static final int HANDOVER_TRANSFER_STATUS_FAILURE = 1;


In HandoverService


if (action.equals(ACTION_BT_OPP_TRANSFER_DONE)) {
    int handoverStatus = intent.getIntExtra(EXTRA_BT_OPP_TRANSFER_STATUS,
    if (handoverStatus == HANDOVER_TRANSFER_STATUS_SUCCESS) {


Basically, you need to register BroadcastReceiver


and then check the additional option EXTRA_BT_OPP_TRANSFER_STATUS

and see if it was a success or a failure.

Since they are not part of the public API, please be aware that this may change in a future version.



All Articles