有什麼方法可以使用Android的內部藍牙將文件發送到其他設備?請舉一個例子。使用android bluetooth發送文件?
7
A
回答
2
這很奇怪的是Android有沒有明確的OBEX API兩種權限。使用OBEX
用於文件共享或者您可以使用this解決方案
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);
(它需要this class -
- Android OBEX:無論如何,看看這個項目)
4
這是一個小功能,您可以使用
/**
* Method to share data via bluetooth
* */
public void bluetoothFunctionality() {
String path = Environment.getExternalStorageDirectory() + "/"
+ Config.FILENAME;
File file = new File(path);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
startActivity(intent);
}
此方法將文件發送到使用默認設備藍牙功能的其他裝置。 在你做這個之前,你必須首先配對這個設備,這是有限制的。 發送不同類型的文件,你必須只改變MIME類型集合類型的方法
在清單文件必須添加像
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
+3
如果我沒有錯,那些權限不是必需的。 – xmen
相關問題
- 1. 使用Android發送推文
- 2. 使用Android發送推文
- 3. 將數據發送至Core Bluetooth Framework Xcode
- 4. Android 1.6上使用backport-android-bluetooth
- 5. 發送數據從android bluetooth到藍色電腦
- 6. Android藍牙文件發送
- 7. 使用ajax發送文件
- 8. 使用TClientDataSets發送文件
- 9. 使用Javascript發送文件
- 10. bluetooth android force關閉
- 11. bluetooth with android and raspberrypi
- 12. Android - 用MMS發送音頻文件
- 13. 更改文件權限:/system/etc/bluetooth/audio.config
- 14. Android-如何使用oAuth發送推文?
- 15. 使用Android intent發送HTML郵件
- 16. 使用Android Intent.ACTION_SEND發送電子郵件
- 17. 使用SMTPLIB.data發送文件附件()
- 18. 如何將文件轉換爲byte []要通過Android中的Bluetooth套接字發送的數組?
- 19. 使用javascript發送文件給用戶
- 20. Android BLUETOOTH連接拒絕
- 21. 如何在Android中使用套接字發送大文件
- 22. 如何使用Android Beam設置發送文件的目錄
- 23. 使用android中的套接字發送文件
- 24. Android使用Content Provider從資產文件夾發送圖像?
- 25. 使用Apache發送Android Volley文件:NoClassDefFoundError:ContentType失敗解決方法
- 26. 如何在Android中使用nfc發送文件
- 27. 使用RTMP在WOWZA發送VIdeo文件在android
- 28. Android - 通過藍牙發送文件
- 29. Android藍牙發送文件問題
- 30. Android MediaPlayer通過POST發送MP3文件
你爲什麼不先google? – Pratik