【问题标题】:Android Beam ContentProvider Uri failsAndroid Beam ContentProvider Uri 失败
【发布时间】:2013-02-10 19:48:42
【问题描述】:

我正在尝试使用 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?

更新:

这是应用程序中的相关代码:

Activity 实现了 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>

【问题讨论】:

  • 您能从您的应用中展示一些相关代码吗? (Android Beam 始终使用蓝牙,目前不支持 WiFi。这与三星 S-Beam 形成鲜明对比,后者始终使用 WiFi Direct,但仅适用于最新的三星 NFC 设备。)
  • 感谢您的澄清!!我用一段代码更新了我的问题。

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


【解决方案1】:

我发现了问题,我必须在我的 Content Provider 中覆盖 openFile(Uri uri, String mode),我必须在其中查询数据库,从光标中检索值,将它们写入文件并返回文件的 ParcelFileDescriptor

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多