如何在android中通过蓝牙发送媒体文件

时间:2012-11-08 04:47:23

标签: android bluetooth media file-transfer

我有一个要求。我需要构建一个应用程序,它使用蓝牙将歌曲,图像等媒体文件发送到另一台设备。我不知道如何做到这一点。任何人都可以从头开始协助让我对如何完成这项工作大致了解。示例代码非常有用。

感谢。

2 个答案:

答案 0 :(得分:2)

我认为你应该阅读一次这个文件。

在此示例中,他们从SD卡路径发送PDF 文件但我认为您也可以发送 像音频和视频一样的媒体文件。

请参阅Bluetooth file transfer Android

答案 1 :(得分:1)

private void envio() {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setType("text/plain");
    File archivo=new File(_path);
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(archivo) );
    ///////////////////pakage manager
    PackageManager pm = getPackageManager();
    List<ResolveInfo> appsList = pm.queryIntentActivities( intent, 1);

    if(appsList.size() > 0) {
        //Toast.makeText(this,"su telefono no cuenta con aplicacion de intercambio de datos",Toast.LENGTH_LONG).show();
    }
    //selleccionar la aplicacion de bluetooth
    String packageName = null;
    String className = null;
    boolean found = false;
    // BluetoothAdapter.checkBluetoothAddress("");
    for(ResolveInfo info: appsList){

      packageName = info.activityInfo.packageName;
      if( packageName.equals("com.android.bluetooth")){
         className = info.activityInfo.name;
         found = true;
         break;// found
      }

    }
    if(! found){
      Toast.makeText(this,"...",
                     Toast.LENGTH_SHORT).show();
      // exit
    }

    intent.setClassName(packageName, className);
    startActivity(intent);


}
相关问题