Android Beam ContentProvider Uri失败

时间:2013-02-10 19:48:43

标签: android bluetooth nfc android-4.2-jelly-bean android-beam

尝试使用从galaxy nexus(运行4.2.1)到nexus7(运行4.2)的setBeamPushUrisCallback来发布内容提供者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),并为当梁成功时要启动的活动添加了intent过滤器。我究竟做错了什么?为什么总是切换到蓝牙而不是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>

1 个答案:

答案 0 :(得分:0)

我发现了问题,我必须覆盖内容提供程序中的openFile(Uri uri, String mode),我必须查询数据库,从游标中检索值,将它们写入文件并返回ParcelFileDescriptor为文件。