如何使用蓝牙在应用程序内发送.apk文件 [英] How to send .apk file inside app using Bluetooth

查看:136
本文介绍了如何使用蓝牙在应用程序内发送.apk文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在应用程序中使用蓝牙发送 .apk 文件?
(例如我们启动app然后使用应用程序内的分享图标发送 .apk 文件)

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)

推荐答案

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

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

这篇关于如何使用蓝牙在应用程序内发送.apk文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆