【问题标题】:sending file via BlueTooth通过蓝牙发送文件
【发布时间】:2014-05-02 19:21:30
【问题描述】:

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

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

【问题讨论】:

    标签: android bluetooth


    【解决方案1】:

    您只需要更改以下行:

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

    intent.setType("application/zip");
    

    【讨论】:

      猜你喜欢
      • 2012-02-14
      • 2011-09-01
      • 1970-01-01
      • 2011-02-23
      • 2018-12-03
      • 2013-09-27
      • 1970-01-01
      相关资源
      最近更新 更多