简体   繁体   中英

android send and receive file through bluetooth

i wrote an app that send / receive file through bluetooth but i want to set this app as a default app to send and receive files!

this is my code

Listener

public class ReceiverModeratorThread extends Thread{

    private final BluetoothServerSocket serverSocket;
    private final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    public ReceiverModeratorThread() {
        super();
        BluetoothServerSocket tmp = null;
        try {
            tmp = bluetoothAdapter
                    .listenUsingInsecureRfcommWithServiceRecord(
                            bluetoothAdapter.getName(),
                            UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")
                    );

        } catch (IOException e) { }

        serverSocket = tmp;
    }

    public void run() {
        Log.d("MyListener", "Run receiver Moderator");
        while (!Thread.interrupted()) {
            Log.d("MyListener", "while");
            try {
                Log.d("MyListener", "start try");
                BluetoothSocket socket = serverSocket.accept();
                Log.d("MyListener", "Run create socket");

                Thread t = new getFileThread(socket);
                t.setDaemon(true);
                t.start();

            } catch (IOException e) {
                Log.d("MyListener", "Run receiver Moderator Exception");
            }


        }
    }

}

i search alot but i can't find any way to set my app as a defualt app to send and receive file

what i have to do? am i use an special UUID?

Explanation when a mobile device send a file to my mobile; my App get that file and work with it after that save when and where i want.

A 'default' send hook is done via Intents described in your manifest. You should add to your Activity the specific Intent filter for sending files.

(Receiving I don't know if it works the same way)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM