20

I would like to implement an application to receive a file from a Bluetooth device.

Before receiving, a notification will be raised to accept an incoming file request.

From there, i would like to activate "accept" and download the file automatically without raising an accept dialog when the user receive a second file from another Bluetooth paired device, without notification disturbance when the user launchs an application.

tshepang
  • 12,111
  • 21
  • 91
  • 136
prasad.gai
  • 2,977
  • 10
  • 58
  • 93
  • Check if this helps: http://stackoverflow.com/questions/6483758/android-programmatically-bluetooth-pairing – Niko Apr 11 '12 at 10:01

3 Answers3

1

You can try using the Bluetooth socket connection to set a client server TCP like connection.

Anurag Ramdasan
  • 4,189
  • 4
  • 31
  • 53
1

I developed an app that include this kind of task, and you can use BluetoothChat example. You must set the secure flag to false: ` boolean secure = false;

        try {
            if (secure) {
                tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE,
                    MY_UUID_SECURE);
            } else {
                tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(
                        NAME_INSECURE, MY_UUID_INSECURE);
            }
        } catch (IOException e) {
            Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e);

        mmServerSocket = tmp;
    }`

And then read the buffer from the InputStream that you can find in ConnectedThread:

while (true) {
            try {

                bytes = mmInStream.read(buffer);
                 /*write bytes in a file*/


            } catch (IOException e) {
                Log.e(TAG, "disconnected", e);
                connectionLost();

                BluetoothChatService.this.start();
                break;
            }
        }
VidaLux
  • 150
  • 3
0

ON ROOTED DEVICES, You can just install only two apps on your phone to achieve your goal.

  1. XPosed Installer
  2. Auto-Accept

This way you hook System service.

import android.util.*;
import de.robv.android.xposed.*;
import de.robv.android.xposed.callbacks.XC_LoadPackage.*;

import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;

public class Tutorial implements IXposedHookLoadPackage
{

    private String TAG="TUTORIAL";
    public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
        if (!lpparam.packageName.equals("com.android.bluetooth"))
        {
            Log.i(TAG,"Not: "+lpparam.packageName);
            return;
        }
        Log.i(TAG,"Yes "+lpparam.packageName);  

        findAndHookMethod("com.android.bluetooth.opp.BluetoothOppManager", lpparam.classLoader, "isWhitelisted", String.class,new XC_MethodHook() {
                @Override
                protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                    Log.v(TAG,"HOOK DONE");
                    param.setResult(true); /* you can compare the sender address(String) with your computer and determine if you return true or just allow the original method to be called after this returns.*/

                }
            });

    }
}

For more information, please visit my answer in SO.

I'll post some direct links here.

Links

Dropbox link of the auto accepting app

Dropbox link of the project files (zip)

Xposed apk site

Towelroot site to root your phone

Auto-Accept github repository

KYHSGeekCode
  • 1,068
  • 2
  • 12
  • 30