Sending an APK via Bluetooth to another device

1.6k views Asked by At

I´m trying to develop an App which can send an .APK file via Bluetooth to another device with an Insecure Rfcomm connection. I´m running self-coded apps on both devices. The apps are not the same but I can still set the UUID, Rfcomm Listener and so on, so the connection should work fine and because of the insecure rfcomm without any alert to accept the transfer. I´ve tried the BluetoothChat example from the Android developer page, but I´ve got problems with changing the code for my purposes. Can anyone give me some snippets of code or any link to an tutorial how to setup Apps for Bluetooth File transfer? Every useful stuff is welcome.

EDIT: You could say I´m trying to develop an app, which can "update" another app on another phone by Bluetooth.

Thanks

1

There are 1 answers

5
Divy Soni On BEST ANSWER

This worked for me:

public void shareApk(Context context) {
        try {

            PackageManager pm = context.getPackageManager();
            ApplicationInfo ai = pm.getApplicationInfo(context.getPackageName(), 0);//context.getPackageName() is used for send my app's apk, you can give package name which you want to share
            File srcFile = new File(ai.sourceDir);
            Intent share = new Intent();
            share.setAction(Intent.ACTION_SEND);
            share.setType("application/vnd.android.package-archive");
            share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(srcFile));
            share.setPackage("com.android.bluetooth");
            context.startActivity(share);
            //context.startActivity(Intent.createChooser(share, context.getString(R.string.share_using)));
        } catch (Exception e) {
            Log.e("ShareApp", e.getMessage());
        }
    }