gpt4 book ai didi

java - 如何使用蓝牙在应用程序内发送 .apk 文件

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:28:53 24 4
gpt4 key购买 nike

有什么方法可以在应用程序中使用蓝牙发送 .apk 文件吗?(例如,我们启动应用程序,然后使用应用程序内的共享图标发送 .apk 文件)

最佳答案

假设你想发送你自己的应用程序的.apk,这很简单:

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

关于java - 如何使用蓝牙在应用程序内发送 .apk 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30011482/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com