【问题标题】:Transfer file programmatically using bluetooth for android version 5.0 and above使用 android 5.0 及更高版本的蓝牙以编程方式传输文件
【发布时间】: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


    【解决方案1】:

    以下在 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+

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-28
      • 1970-01-01
      • 1970-01-01
      • 2018-08-28
      • 2011-06-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多