Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send .apk file inside app using Bluetooth

Tags:

java

android

Is there any way to send .apk file using Bluetooth inside the application? (for example we launch app and then send .apk file using share icon inside app)

like image 492
Erfan Eghterafi Avatar asked May 03 '15 07:05

Erfan Eghterafi


1 Answers

Assuming you want to send your own app's .apk, it's quite simple:

// Get current ApplicationInfo to find .apk path
ApplicationInfo app = getApplicationContext().getApplicationInfo();
String filePath = app.sourceDir;

Intent intent = new Intent(Intent.ACTION_SEND);

// MIME of .apk is "application/vnd.android.package-archive".
// but Bluetooth does not accept this. Let's use "*/*" instead.
intent.setType("*/*");

// Only use Bluetooth to send .apk
intent.setPackage("com.android.bluetooth");

// Append file and send Intent
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filePath)));
startActivity(Intent.createChooser(intent, "Share app"));
like image 85
ByteHamster Avatar answered Sep 19 '22 05:09

ByteHamster