I'm trying to send a file via bluetooth, but when I'm choosing a file , nothing happens . I'm trying to do this by clicking on the device ( ListView ) > then select a file (after selection activity: files manager) > send selected file to selected (from ListView) device, but it doesn't work. Please tell me how to send file properly, taking into account the above sequence.
BluetoothActivity.java:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bluetooth);
toggleButton = (ToggleButton) findViewById(R.id.toggleButton);
listview = (ListView) findViewById(R.id.listView);
// ListView Item Click Listener
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// ListView Clicked item value
String itemValue = (String) listview.getItemAtPosition(position);
String MAC = itemValue.substring(itemValue.length() - 17);
BluetoothDevice bluetoothDevice = bluetoothAdapter.getRemoteDevice(MAC);
// Initiate a connection request in a separate thread
pickFile();
ConnectingThread t = new ConnectingThread(bluetoothDevice);
t.start();
}
});
adapter = new ArrayAdapter
(this,android.R.layout.simple_list_item_1);
listview.setAdapter(adapter);
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
}
in onActivityResult:
super.onActivityResult(requestCode, resultCode, data);
try {
Uri selectedImage = data.getData();
Intent sendIntent = new Intent();
sendIntent.setType("*/*");
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM, selectedImage);
//startActivity(Intent.createChooser(sendIntent, ""));
startActivity(Intent.createChooser(sendIntent, "Send file via:"));
}
catch(Exception e)
{
}
public void pickFile() in BluetoothActivity.java:
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("file/*");
startActivityForResult(i, FILE_SELECT_CODE);
activity_bluetooth.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.abuk.kuba.androidconnection.BluetoothActivity">
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/toggleButton"
android:textOn="Bluetooth On"
android:textOff="Bluetooth Off"
android:onClick="onToggleClicked" />
<ListView
android:layout_width="wrap_content"
android:layout_height="340dp"
android:id="@+id/listView" />
</LinearLayout>