gpt4 book ai didi

android - 通过蓝牙发送文件

转载 作者:太空宇宙 更新时间:2023-11-03 13:24:12 24 4
gpt4 key购买 nike

实际上我正在开发一个免费的应用程序,当按下某个按钮时需要通过蓝牙分享自己并且我已经使用了这段代码(我尝试从 sd 卡获取文件):

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
// Device does not support Bluetooth
}

if (!mBluetoothAdapter.isEnabled()) {
Toast.makeText(getApplicationContext(), "Bluetooth is turned off, please enable it to proceed!", Toast.LENGTH_LONG).show();
}
else {
File sourceFile = findFile(Environment.getExternalStorageDirectory(),"E-charge.apk");
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("application/vnd.android.package-archive");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(sourceFile) );
startActivity(intent);
}

这是与此按钮所在的 Activity 相关的 list :

<activity
android:name=".main.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="*/*" />
<data android:host="*"/>
<data android:pathPattern="*.*\\.apk" />
</intent-filter>
</activity>

但是,当我按下按钮(在 android 2.3.5 中)时,它让我可以选择仅通过电子邮件而不是蓝牙发送,所以我可以请求您的帮助以使其正常工作吗?

我还为蓝牙用户添加了权限,所以情况并非如此!

最佳答案

您只需要更改以下行:

intent.setType("application/vnd.android.package-archive");

intent.setType("application/zip");

关于android - 通过蓝牙发送文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22795232/

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