Note that there are some explanatory texts on larger screens.

plurals
  1. POSending a File using Bluetooth OBEX Object Push Profile (OPP)
    primarykey
    data
    text
    <p>Is there any way to send a file using the android bluetooth API using OBEX?</p> <p>I need to send a file to a printer that supports OBEX OPP only.</p> <p>I can send the file using the android intent ACTION_SEND to the printer with no problems, but I'd need to send it programmatically..</p> <p>I can connect to the bluetooth printer using OBEX OPP UUID (1105) with the method createRfcommSocketToServiceRecord(), but then I should follow obex specifications to send a file using OBEX.. it isn't as simple as writing bytes to the output socket..</p> <p>But if the intent ACTION_SEND can handle this, why there isn't any api for developers to send the files?</p> <p>I also checked some third party libs like BlueCove, but I still didn't get it to work.. (Nexus One &amp; Galaxy Tab throw an exception saying that native library bluecove_armv71 isn't available.. and LG Optimus One says that bluecove_armv61 isn't available..)</p> <p>i'm stuck, any ideas?</p> <p><strong>WORKING SOLUTION</strong></p> <p>For anyone trying to send a file to a bluetooth device with no luck, I provide a working solution using content providers (thanks to KPBird):</p> <p>Grab the java class <em>BluetoothShare</em> from <a href="http://hi-android.info/src/com/android/bluetooth/opp/BluetoothShare.java.html">here</a></p> <p>Than, the following code sends a file on the SD card to a bluetooth device:</p> <pre><code>BluetoothDevice device; String filePath = Environment.getExternalStorageDirectory().toString() + "/file.jpg"; ContentValues values = new ContentValues(); values.put(BluetoothShare.URI, Uri.fromFile(new File(filePath)).toString()); values.put(BluetoothShare.DESTINATION, device.getAddress()); values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND); Long ts = System.currentTimeMillis(); values.put(BluetoothShare.TIMESTAMP, ts); Uri contentUri = getContentResolver().insert(BluetoothShare.CONTENT_URI, values); </code></pre> <p><strong>UPDATE</strong></p> <p>Some people are experiencing problems with the solution above, it has been tested on the following devices:</p> <p>Works on:</p> <ul> <li>LG Optimus One (Android 2.1)</li> <li>HTC Desire (Android 2.2)</li> <li>Google Nexus One (Android 2.2 and 2.3)</li> <li>Samsung Galaxy S2 (Android 4.0.3)</li> <li>HTC Amaze (Android 2.3.4)</li> </ul> <p>Has issues on:</p> <ul> <li>LG P500 (Android 2.3.3)</li> <li>Galaxy TAB P500 (Android 2.2)</li> <li>Google Nexus S (Android 4.1.2)</li> </ul> <p>If you are able to test this snippet on devices which are not listed above, please <strong>provide the details of the devices</strong> (brand, name, android version, etc..) with which you tested it, and the test results, in a comment below, I will update the question including your data.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload