1

Beconsを使ってアプリを開発しようとしています。私はこの小さなEstimote Beaconを持っています。この短い説明で説明されている手順を実行しました。ライブラリをgithubからダウンロードし、 myproject に追加しました。

私のコードは次のようになります。

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アプリでスキャンしたときにすべてのビーコンが表示されるため、デバイスに問題はありません。私はどんな提案にも感謝します

4

1 に答える 1

1

使用している Estimote SDK のバージョンは? 最新の 0.4 バージョンですか?最新としてチェックすると、ログタグが異なります。

ログに「サービスをバインドできませんでした」と表示されている場合は、それcom.estimote.sdk.service.BeaconServiceが見つからなかったことを意味します。SDK の初期バージョンは、 1 つではなくパッケージに含まれていBeaconServiceたことに注意してください。com.estimote.sdkcom.estimote.sdk.service

ところで、Estimote SDK でデモを実行できましたか?

于 2014-02-25T21:38:27.933 に答える