0

我已经编写了在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

任何想法?

4

1 回答 1

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);
于 2012-09-29T06:44:41.530 回答