我正在尝试使用 setBeamPushUrisCallback 从 Galaxy nexus(运行 4.2.1)到 nexus7(运行 4.2)发送内容提供者 uri。两台设备都安装了应用程序,但在 NFC 切换到蓝牙期间传输失败,我得到的例外是:
02-10 13:33:32.762: D/BluetoothOppUtility(23916): closeSendFileInfo: uri=content://com.android.beam.Beam/msgs/2
02-10 13:33:32.762: W/dalvikvm(23916): threadid=21: thread exiting with uncaught exception (group=0x40d70930)
02-10 13:33:32.770: E/AndroidRuntime(23916): FATAL EXCEPTION: Bluetooth Share Service
02-10 13:33:32.770: E/AndroidRuntime(23916): java.lang.NullPointerException
02-10 13:33:32.770: E/AndroidRuntime(23916): at com.android.bluetooth.opp.BluetoothOppUtility.closeSendFileInfo(BluetoothOppUtility.java:327)
02-10 13:33:32.770: E/AndroidRuntime(23916): at com.android.bluetooth.opp.BluetoothOppService.insertShare(BluetoothOppService.java:614)
02-10 13:33:32.770: E/AndroidRuntime(23916): at com.android.bluetooth.opp.BluetoothOppService.access$1800(BluetoothOppService.java:69)
02-10 13:33:32.770: E/AndroidRuntime(23916): at com.android.bluetooth.opp.BluetoothOppService$UpdateThread.run(BluetoothOppService.java:472)
02-10 13:33:32.941: E/NfcHandover(693): Handover transfer failed
我已经在我的清单中声明了提供者(我可以在我的应用程序中很好地查询 uri)并添加了意图过滤器,以便在梁成功时启动要启动的活动。我究竟做错了什么?为什么总是切换到蓝牙而不是wifi?
更新:
这是应用程序中的相关代码:
该活动实现了 CreateBeamUrisCallback 并在 onCreate 中:
mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
if (mNfcAdapter == null) return; // NFC not available on this device
mNfcAdapter.setBeamPushUrisCallback(this, this);
和覆盖的方法:
@Override
public Uri[] createBeamUris(NfcEvent event) {
Uri uri = Uri.parse("content://com.android.beam.Beam/msgs/2");
return new Uri[]{uri};
}
显现:
<provider
android:name="com.example.android.beam.BeamContentProvider"
android:authorities="com.android.beam.Beam"
android:exported="true"/>
<activity android:name="com.example.android.beam.Beam"
android:label="@string/app_name"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/vnd.com.example.msgs" />
</intent-filter>
</activity>