【问题标题】:estimote beacons - could not bind service估计信标 - 无法绑定服务
【发布时间】:2014-02-22 16:34:09
【问题描述】:

我尝试使用 Becons 开发应用程序。我有this 小型 Estimote Beacon。我做了this 简短说明中描述的步骤。我从github 下载了库,并将其添加到了我的项目中。

我的代码是这样的,

public class MainActivity extends Activity {

 BeaconManager beaconManager;

  private static final String ESTIMOTE_PROXIMITY_UUID = "B9407F30-F5F8-466E-AFF9-25556B57FE6D";
  private static final Region ALL_ESTIMOTE_BEACONS = new Region(ESTIMOTE_PROXIMITY_UUID, null, null);

  final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Log.e(TAG, "onCreate");

    beaconManager = new BeaconManager(getApplicationContext());

    if(beaconManager.isBluetoothEnabled())
    {
        Toast.makeText(getApplicationContext(), "Bl włączone", Toast.LENGTH_LONG).show();
    }
    else
    {
        Toast.makeText(getApplicationContext(), "Bl wyłączone", Toast.LENGTH_LONG).show();
    }

      beaconManager.setRangingListener(new BeaconManager.RangingListener() {
        @Override public void onBeaconsDiscovered(Region region, List<Beacon> beacons) {
          Log.d(TAG, "Ranged beacons: " + beacons);
          Toast.makeText(MainActivity.this,"Ranged beacons: " + beacons, Toast.LENGTH_LONG).show();
        }           
      });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
protected void onStart() {
    // TODO Auto-generated method stub
    super.onStart();
    Log.e(TAG, "onStart");
    beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
        @Override public void onServiceReady() {
          try {
            beaconManager.startRanging(ALL_ESTIMOTE_BEACONS);
            Toast.makeText(getApplicationContext(), "try start ranging", Toast.LENGTH_LONG).show();

          } catch (RemoteException e) {
            Log.e(TAG, "Cannot start ranging", e);
            Toast.makeText(getApplicationContext(), "Cannot start ranging", Toast.LENGTH_LONG).show();
          }
        }
      });
}

@Override
protected void onStop() {
    // TODO Auto-generated method stub
    super.onStop();
      // Should be invoked in #onStop.
      try {
        beaconManager.stopRanging(ALL_ESTIMOTE_BEACONS);
      } catch (RemoteException e) {
        Log.e(TAG, "Cannot stop but it does not matter now", e);
        Toast.makeText(getApplicationContext(), "Cannot stop but it does not matter now", Toast.LENGTH_LONG).show();
      }


}

@Override
protected void onDestroy() {
    // TODO Auto-generated method stub
    super.onDestroy();
     // When no longer needed. Should be invoked in #onDestroy.
      beaconManager.disconnect();
}   

}

和清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.beacon"
android:versionCode="1"
android:versionName="1.0" >

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

 <!-- Needed permissions in order to scan for beacons. -->
 <uses-permission android:name="android.permission.BLUETOOTH"/>
 <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

 <!-- Declaration that this app is usable on phones with Bluetooth Low Energy. -->
  <uses-feature android:name="android.hardware.bluetooth_le" 
    android:required="true"/>

 <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
      <service android:name="com.estimote.sdk.service.BeaconService"
     android:exported="false"/>
    <activity
        android:name="com.example.beacon.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>        
   < /application>
</manifest>

显示在页面上,我收到此消息

02-22 05:27:08.711: A/BeaconManager(7227): Could not bind service

对我来说,这意味着创建 BeaconManager 有问题,但不知道如何解决。设备没有问题,因为当我通过iBeacon Locate 应用程序扫描它时,我看到了所有信标。如果有任何建议,我将不胜感激

【问题讨论】:

  • 对不起,我不知道如何使用 Estimote SDK,但既然你知道 iBeacon Locate 应用程序可以工作,你可以试试它所基于的 Android iBeacon 库。这个库的主要好处是它是开源的,因此如果出现问题,更容易获得社区帮助。 developer.radiusnetworks.com/ibeacon/android充分披露:我是图书馆的作者。
  • 明天我会试试这个库;)谢谢这个评论

标签: android bluetooth-lowenergy ibeacon-android


【解决方案1】:

您使用的是哪个版本的 Estimote SDK?它是最新的0.4版本吗?将其检查为最新具有不同的日志标签。

如果日志显示“无法绑定服务”,则表示无法找到 com.estimote.sdk.service.BeaconService。请注意,SDK BeaconService 的早期版本在 com.estimote.sdk 包中,而不是在 com.estimote.sdk.service 包中。

顺便说一句,你能在 Estimote SDK 中运行演示吗?

【讨论】:

  • 是的,我有最新版本的 sdk 0.4。我为此活动从这个估计中导入 import com.estimote.sdk.Beacon;导入 com.estimote.sdk.BeaconManager;导入 com.estimote.sdk.Region;我没有尝试运行演示
  • 我将登录清单从 com.estimote.sdk.service.BeaconService 更改为 com.estimote.sdk.BeaconService,我认为它有效
猜你喜欢
  • 2014-08-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-05
  • 2023-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多