我已经编写了在android中使用蓝牙传输文件的代码:
ContentValues values = new ContentValues();
values.put(BluetoothShare.URI, Uri.parse("file:///sdcard/jokes.txt").toString());
values.put(BluetoothShare.DESTINATION, "0C:71:5D:BA:0E:A8");
values.put(BluetoothShare.TOTAL_BYTES, length);
values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);
Long ts = System.currentTimeMillis();
values.put(BluetoothShare.TIMESTAMP, ts);
getContentResolver().insert(BluetoothShare.CONTENT_URI, values);
它在HTC Desire(Android 4.0)上运行良好,但它不适用于三星Galaxy ace(Android 2.3.6)。我希望这些代码能够在每台设备上运行。
在Micromax(Android 2.3.4)中,我在最后一行收到错误,如下所示,
Exception: java.lang.IllegalArgumentException: Unknown URL content://com.android.bluetooth.opp/btopp
任何想法?
答案 0 :(得分:0)
尝试按以下方式发送,
File file = new File ( Environment.getExternalStorageDirectory() + "/jokes.txt" );
ContentValues values = new ContentValues();
values.put( BluetoothShare.URI, Uri.fromFile( file ).toString() );
values.put( BluetoothShare.DESTINATION, "0C:71:5D:BA:0E:A8" );
values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);
Long ts = System.currentTimeMillis();
values.put(BluetoothShare.TIMESTAMP, ts);
getContentResolver().insert(BluetoothShare.CONTENT_URI, values);