How to accept bluetooth received file in Android application?

后端 未结 3 660
醉梦人生
醉梦人生 2021-02-12 13:41

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 r

3条回答
  •  孤城傲影
    2021-02-12 14:13

    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

提交回复
热议问题