2016-04-16 23 views
1

私はiBeaconsを検出するために、Androidのビーコンライブラリを使用しようとするが、それは動作しませんiBeaconを検出するAndroidビーコンライブラリが失敗します。公平ではない:(

出力logcatイストからわずか:。

I/SELinux﹕ Function: selinux_android_load_priority [0], There is no sepolicy file. I/SELinux﹕ Function: selinux_android_load_priority , spota verifySig and checkHash pass. priority version is VE=SEPF_GT-I9195_4.4.2_0046 I/SELinux﹕ selinux_android_seapp_context_reload: seapp_contexts file is loaded from /data/security/spota/seapp_contexts E/dalvikvm﹕ >>>>> Normal User E/dalvikvm﹕ >>>>> com.cyberland.felix.ibeaconexample [ userId:0 | appId:10176 ] D/dalvikvm﹕ Late-enabling CheckJNI I/PersonaManager﹕ getPersonaService() name persona_policy D/BeaconParser﹕ Parsing beacon layout: m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25 D/BeaconParser﹕ Parsing beacon layout: m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24 W/ModelSpecificDistanceCalculator﹕ Cannot find match for this device. Using default W/ModelSpecificDistanceCalculator﹕ Cannot find match for this device. Using default E/MonitoringStatus﹕ Deserialization exception, message: $s

そしてちょうど

D/BluetoothAdapter﹕ stopLeScan()

何度も何度も...

は、私はちょうどoficialページから変形例:

public class MainActivity extends Activity implements BeaconConsumer { 
protected static final String TAG = "MainActivity"; 
private BeaconManager beaconManager; 
private static final int PERMISSION_REQUEST_COARSE_LOCATION = 1; 

private BluetoothAdapter mBluetoothAdapter; 



@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    /* 
    mBluetoothAdapter = ((BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter(); 
    mBluetoothAdapter.startLeScan(new BluetoothAdapter.LeScanCallback() { 
     @Override 
     public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) { 
      Log.d(TAG, "Scanned BLE device with mac: " + device.getAddress()); 
     } 
    }); 
    */ 
    beaconManager = BeaconManager.getInstanceForApplication(this); 
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24")); 
    beaconManager.bind(this); 




} 


@Override 
protected void onDestroy() { 
    super.onDestroy(); 
    beaconManager.unbind(this); 

} 


@Override 
public void onBeaconServiceConnect() { 
    beaconManager.setRangeNotifier(new RangeNotifier() { 
     @Override 
     public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) { 
      if (beacons.size() > 0) { 
       Log.i(TAG, "The first beacon I see is about " + beacons.iterator().next().getDistance() + " meters away."); 
      } 
     } 
    }); 

    try { 
     beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null)); 
    } catch (RemoteException e) { } 
} 

私はあなたが私を助けることができると思います!

よろしく、

フェリックス
+0

お使いの携帯電話はどのバージョンのAndroidを搭載していますか?あなたが設定 - >場所に行くとどうなりますか?高精度、デバイスのみ、またはバッテリー節約のいずれかのモードがオンかオフか、どのモードですか? – davidgyoung

+0

携帯電話は4.4.2(サムスンS4ミニ)、場所は高精度です。私は、プレイストアのアプリでiBeaconを見つけることができました。 – Cyberlander

答えて

0

問題は、デバイスでスキャンするための適切な権限が付与されていない可能性があります。この理論をテストするには、メインアクティビティのonCreateメソッドに次のコードを追加し、返される内容を確認してください。 Nexus 5Xに表示される出力例を以下に示します。

 try { 
      PackageInfo info = getPackageManager().getPackageInfo(this.getPackageName(), PackageManager.GET_PERMISSIONS); 
      Log.d(TAG, "SDK "+Build.VERSION.SDK_INT+" App Permissions:"); 
      if (info.requestedPermissions != null) { 
       for (String p : info.requestedPermissions) { 
        int grantResult = this.checkPermission(p, android.os.Process.myPid(), android.os.Process.myUid()); 
        if (grantResult == PackageManager.PERMISSION_GRANTED) { 
         Log.d(TAG, p+" PERMISSION_GRANTED"); 
        } 
        else { 
         Log.d(TAG, p+" PERMISSION_DENIED: "+grantResult); 
        } 
       } 
      } 
     } catch (Exception e) { 
      Log.d(TAG, "Cannot get permissions due to error", e); 
     } 

出力例:あなたはあなたのデバイス上の出力から欠落している上記の権限のいずれかが表示された場合

04-17 12:04:01.943 30624-30624/? D/MonitoringActivity: SDK 23 App Permissions: 
04-17 12:04:01.944 30624-30624/? D/MonitoringActivity: android.permission.INTERNET PERMISSION_GRANTED 
04-17 12:04:01.945 30624-30624/? D/MonitoringActivity: android.permission.BLUETOOTH PERMISSION_GRANTED 
04-17 12:04:01.945 30624-30624/? D/MonitoringActivity: android.permission.BLUETOOTH_ADMIN PERMISSION_GRANTED 
04-17 12:04:01.946 30624-30624/? D/MonitoringActivity: android.permission.RECEIVE_BOOT_COMPLETED PERMISSION_GRANTED 
04-17 12:04:01.946 30624-30624/? D/MonitoringActivity: android.permission.ACCESS_COARSE_LOCATION PERMISSION_GRANTED 

、ソリューションは、手動でのAndroidManifest.xmlにACCESS_COARSE_LOCATION場所の権限を追加することであってもよいです。 PERMISSION_DENIEDが表示されている場合は、別の問題かもしれません。あなたのデバイスでビーコンスキャンを開始する前にアクセス許可のチェックをスキップすることができます。これはAndroid Beacon Libraryのバージョンをこのチェックを行わない2.7に一時的にダウングレードすることで可能になります。

+0

ありがとうございます! ACCESS_COARSE_LOCATIONがポイントでした。 – Cyberlander

+0

デバッグ出力に権限がないと言っていますか?それとも、許可が拒否されたと言っているのですか?また、Android StudioやEclipseを使用していますか?フォローアップを申し訳ありませんが、あなたがどのような問題を抱えていたのか、それをどのように修正して他の人を助けることができるのかを正確に理解したいと思います。 – davidgyoung

+0

権限がなくなり、Androidスタジオを使用しています。私はEclipsedと同じ問題を抱えていました。マニフェストにACCESS_COARSE_LOCATION権限を追加すると、問題が解決しました。 – Cyberlander

0

フム、公式の例は、(Androidのビーコン・ライブラリ・リファレンス)同じ出力を生成します。私はそれを説明することはできません。

関連する問題