It is already asked but i didn\'t find any solution. For bluetooth application i am using the bluetoothShare.class
.
My source code for sending the file to
This code works with firmware from MediaTek. Tested on Android 4.0.4. Sends the file, without asking anything from the user
public boolean SendFileViaBluetoothOPP(String file_path, String destinationMAC){
BluetoothAdapter btadapter = BluetoothAdapter.getDefaultAdapter();
if(btadapter == null)
return false;
BluetoothDevice btdev = btadapter.getRemoteDevice(destinationMAC);
if(btdev == null)
return false;
Uri uri = Uri.fromFile(new File(file_path));
Intent shareIntent = new Intent(Intent.ACTION_SEND)
.putExtra(Intent.EXTRA_STREAM, uri)
.setType("application/zip");
List resolvedActivities = getPackageManager().queryIntentActivities(shareIntent, 0);
boolean found = false;
for(ResolveInfo actInfo: resolvedActivities){
if(actInfo.activityInfo.packageName.equals("com.mediatek.bluetooth"))
{
shareIntent.setComponent( new ComponentName(actInfo.activityInfo.packageName, actInfo.activityInfo.name ) );
shareIntent.putExtra("com.mediatek.bluetooth.sharegateway.extra.DEVICE_ADDRESS", btdev);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
found = true;
break;
}
}
if(found){
startActivity(shareIntent);
return true;
}
return false;
}
On older phone from MediaTek with Android 2.2.1 this code launches BluetoothDevicePicker to complete the operation.