我要求将指定文件(例如,test1.pg)发送到所有配对的手机(没有任何确认)。我不希望显示蓝牙设备选择窗口并从那里选择设备。我有以下代码,但会发生什么是它显示蓝牙设备选择器屏幕,它希望选择设备和文件正在发送。请找到我打算为所有连接的手机执行的代码段。
File f = new File(Environment.getExternalStorageDirectory(),"test1.jpg");
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("image/*");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
sendIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, device.getAddress());
sendIntent.setClassName("com.android.bluetooth", "com.broadcom.bt.app.opp.OppLauncherActivity");
//sendIntent.setClassName("com.android.bluetooth", "com.android.bluetooth.opp.BluetoothOppLauncherActivity");
// sendIntent.setPackage("com.android.bluetooth");
startActivity(sendIntent);
我的AndroidManifest文件是:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bt_test2"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<permission android:name="android.permission.BLUETOOTH" android:label="BLUETOOTH"></permission>
<permission android:name="android.permission.BLUETOOTH_ADMIN"></permission>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:debuggable="true">
<activity
android:name="com.example.bt_test2.MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.broadcom.bt.app.opp.OppLauncherActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="video/*" />
<data android:mimeType="audio/*" />
</intent-filter>
</activity>
</application>
</manifest>