How to send .apk file inside app using Bluetooth

前端 未结 1 969
予麋鹿
予麋鹿 2021-02-09 14:39

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 a

1条回答
  •  野的像风
    2021-02-09 15:10

    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"));
    

    0 讨论(0)
提交回复
热议问题