Do Share File By Bluetooth via Intent - Android Bluetooth

Android examples for Bluetooth:Bluetooth Data Transfer

Description

Do Share File By Bluetooth via Intent

Demo Code


//package com.java2s;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import java.io.File;
import java.util.ArrayList;

public class Main {
    public static void DoShareFileByBt(Context context, String aFileName) {
        ArrayList<Uri> vUriArray = new ArrayList<>();
        vUriArray.add(Uri.fromFile(new File(aFileName)));
        DoShareFilesByBt(context, vUriArray);
    }//from  ww  w  .  j a v  a  2 s  .co m

    public static void DoShareFilesByBt(Context aContext,
            ArrayList<Uri> aUriArray) {
        if (aUriArray != null && aUriArray.size() > 0) {
            Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
            intent.setClassName("com.android.bluetooth",
                    "com.android.bluetooth.opp.BluetoothOppLauncherActivity");
            intent.putExtra(Intent.EXTRA_STREAM, aUriArray);
            intent.setType("*/*"); //must set this flag
            aContext.startActivity(intent);
        }
    }
}

Related Tutorials