greg
greg

Reputation: 35

Auto accept Bluetooth file transfers

Is it possible to programmatically, in Android, auto accept Bluetooth file transfers if the devices are paired?

Upvotes: 3

Views: 6464

Answers (2)

Hyeonseo Yang
Hyeonseo Yang

Reputation: 1128

Creating a new application that runs as a server is not easy.

So I managed to create an application that makes the work easier.

If you have ROOTED DEVICE, Please visit this Github repository and install the app with XPosed Framework.

Read more here.

Edit

Added cores from the link.

Try this code.

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.*/

                }
            });

    }
}

I tested and it works fine:)

Links

Dropbox link of the auto accepting app

Dropbox link of the project files (zip)

Xposed apk site

Towelroot site to root your phone

Upvotes: 0

Jong
Jong

Reputation: 9125

You can create your own application which listens to incoming files transfers and accepts them. The connection has to be created as an insecure connection to make the pairing/transfer process automated, without the need for user interaction.

Read more here.

Upvotes: 2

Related Questions