2015-09-05 22 views
0

我想使用蓝牙传输文件,我使用ContentValues代码,但它不适用于Android 4.1及更高版本,我希望为5.0及更高版本创建此功能。以编程方式使用蓝牙为Android 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); 

回答

0

不是作品的Android 5.1继为我工作。

Intent intent = new Intent(); 
intent.setAction(Intent.ACTION_SEND); 
intent.setType("*/*"); 
intent.putExtra(Intent.EXTRA_STREAM, uri); 
startActivity(intent); 

,只是想分享BluetoothShare可能不支持Android 4.0以上版本