suresh cheemalamudi
suresh cheemalamudi

Reputation: 6240

how to send media files via bluetooth in android

I have a requirement. I need to build an app, which uses Bluetooth to send media files like songs, images etc to another device. I have no knowledge about how to do this. Can anyone assist from scratch to make me get a rough idea about how getting this done. Sample code would be very helpful.

Thanks.

Upvotes: 1

Views: 6559

Answers (2)

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


}

Upvotes: 1

Chintan Khetiya
Chintan Khetiya

Reputation: 16142

I think you should read this document once .

In this example they are sending PDF file form SD Card Path but i think you can also send media file like audio and video as same.

see this : Bluetooth file transfer Android

Upvotes: 2

Related Questions