AltBeacon:服务中的 BeaconConsumer 不工作

AltBeacon: BeaconConsumer in Service Not Working

在这个话题中 但是当我把代码放在清单中时

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ubiquitous.beaconone.tablet"
android:versionCode="3"
android:versionName="2.0" >

<uses-sdk
    android:minSdkVersion="19"
    android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

<application
    android:icon="@drawable/logo"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".Activities.MainActivity"
        android:label="@string/app_name"
        android:launchMode="singleInstance"
        android:taskAffinity="">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Activities.ScanningActivity"/>

    <service
        android:name="org.altbeacon.beacon.service.BeaconService"
       android:enabled="true"
        android:exported="true"
        android:isolatedProcess="false"></service>
    <service
        android:name="org.altbeacon.beacon.BeaconIntentProcessor"
        android:enabled="true"></service>

</application>

我遇到了一个错误:

错误:(48, 13) 属性服务#org.altbeacon.beacon.service.BeaconService@exported value=(true) 来自 AndroidManifest.xml:48:13

错误:(48, 13) 任务“:app:processDebugManifest”执行失败。

Manifest merger failed : Attribute service#org.altbeacon.beacon.service.BeaconService@exported value=(true) from AndroidManifest.xml:48:13 is also present at org.altbeacon:android-beacon-library:2.1.4:27:13 value=(false) Suggestion: add 'tools:replace="android:exported"' to element at AndroidManifest.xml:45:9 to override

删除

 android:exported="true"

来自 org.altbeacon.beacon.service.BeaconService

的服务标签

使用 Android Beacon Library 时,您通常不想将其服务声明放入您的清单中,因为该库本身包含其自己的 AndroidManifest.xml 文件并使用称为清单合并的过程(当使用 Android Studio) 将库中的条目合并到应用的清单中。

此过程将复制此处显示的清单条目:https://github.com/AltBeacon/android-beacon-library/blob/master/src/main/AndroidManifest.xml

在问题中显示的代码中,冲突条目已放入应用程序的清单中,因此合并失败。这是错误信息的意思。

冲突的确切来源是属性 android:exported="true"。该属性的值已在最新版本的库中更改为 false。

您可以通过多种方式解决此问题。仅选择以下一项

  1. 从清单中删除这两个服务条目。合并将自动添加适当的条目。

  2. android:exported="true"改为android:exported="false"

  3. android:exported="true"

  4. 之后添加tools:replace="android:exported"
  5. 关闭清单合并并自行输入所有条目。如果要自动启动,您还需要复制 StartupBroadcastReceiver 条目。

在此处查看相关讨论:http://altbeacon.github.io/android-beacon-library/alternate-configuration.html