【发布时间】:2015-09-05 06:22:15
【问题描述】:
我想使用蓝牙传输文件,我使用了 ContentValues 代码,但它不适用于 android 4.1 及更高版本,我想为 5.0 及更高版本的模型创建此功能。
我尝试了以下 2 件事,但没有成功。
代码 1:使用 ContentValues(支持 4.0 及以下版本)
ContentValues values = new ContentValues();
values.put(BluetoothShare.URI, "file://"+selectedFile.getAbsolutePath());
values.put(BluetoothShare.DESTINATION, MACAddress);
values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);
Long ts = System.currentTimeMillis();
values.put(BluetoothShare.TIMESTAMP, ts);
getContentResolver().insert(BluetoothShare.CONTENT_URI, values);
代码 2:不适用于任何版本
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("image/jpeg");
sharingIntent.setComponent(new ComponentName("com.android.bluetooth", "com.android.bluetooth.opp.BluetoothOppLauncherActivity"));
sharingIntent.putExtra(BluetoothShare.URI, "file://"+selectedFile.getAbsolutePath());
startActivity(sharingIntent);
【问题讨论】:
标签: android file bluetooth transfer