通过BlueTooth发送文件

时间:2014-04-01 19:33:05

标签: android bluetooth

实际上我正在开发一个免费的应用程序,当按下某个按钮时我需要通过蓝牙共享自己并且我已经使用了这个代码(我尝试从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
        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中)时,它为我提供了仅通过电子邮件而不是蓝牙发送的选项,那么我可以请求你的帮助以使其正常工作吗?

我也为蓝牙家伙添加了权限,但事实并非如此!

1 个答案:

答案 0 :(得分:4)

您只需要更改以下行:

  

intent.setType( “应用程序/ vnd.android.package - 归档”);

intent.setType("application/zip");
相关问题