2016-12-09 4 views
0

私はAndroid 6.0携帯を持っています。このアプリはビーコンを表示しません。 I am getting this errorAndroid 6.0にビーコンが表示されない

I/BluetoothLeScanner: startRegisteration: mLeScanClients = {org.altbeacon.beacon.service.scanner.CycledLeScannerForLollipop $ 4 @ 5445b45 = android.bluetooth.le.BluetoothLeScanner $ BleScanCallbackWrapper @ d9ce5fa}. 

私を助けることができますか?

public class MainActivity extends AppCompatActivity implements BeaconConsumer { 
private BeaconManager beaconManager; 
private Beacon nearestBeacon; 

private static final int PERMISSION_REQUEST_COARSE_LOCATION = 1; 
private static final String TAG = "Beacon"; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    beaconManager=BeaconManager.getInstanceForApplication(this); 
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25")); 
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24")); 
    beaconManager.setBackgroundScanPeriod(TimeUnit.SECONDS.toMillis(20)); 
    beaconManager.setBackgroundBetweenScanPeriod(TimeUnit.SECONDS.toMillis(10)); 
    beaconManager.bind(this); 



    if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.M){ 
    if(this.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION)!=PackageManager.PERMISSION_GRANTED){ 
     final AlertDialog.Builder builder=new AlertDialog.Builder(this); 
     builder.setTitle("This app needs location acces"); 

     builder.setMessage("Please grant location.."); 
     builder.setPositiveButton(android.R.string.ok,null); 
     builder.setOnDismissListener(new DialogInterface.OnDismissListener() { 
      @Override 
      public void onDismiss(DialogInterface dialogInterface) { 
      requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},PERMISSION_REQUEST_COARSE_LOCATION); 
      } 
     }); 
     builder.show(); 

    } 
} 
} 

@Override 
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 
    switch (requestCode) { 
     case PERMISSION_REQUEST_COARSE_LOCATION: { 
      if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { 
       Log.d(TAG, "coarse location permission granted"); 
      } else { 
       final AlertDialog.Builder builder = new AlertDialog.Builder(this); 
       builder.setTitle("Functionality limited"); 
       builder.setMessage("Since location access has not been granted, this app will not be able to discover beacons when in the background."); 
       builder.setPositiveButton(android.R.string.ok, null); 
       builder.setOnDismissListener(new DialogInterface.OnDismissListener() { 

        @Override 
        public void onDismiss(DialogInterface dialog) { 
        } 

       }); 
       builder.show(); 
      } 
      return; 
     } 
    } 
} 

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

@Override 
    public void onBeaconServiceConnect() { 
    beaconManager.addRangeNotifier(new RangeNotifier() { 
     @Override 
     public void didRangeBeaconsInRegion(Collection<Beacon> collection, Region region) { 
      if(collection.size()>0){ 
       Log.d(TAG,collection.toString()); 
       List beaconList=new ArrayList(collection); 

      } 
     } 
    }); 
    try { 
     beaconManager.startMonitoringBeaconsInRegion(new Region("myRangingUniqueID",null,null,null)); 
    } catch (RemoteException e) { 
     e.printStackTrace(); 
    } 

} 
public void getNearestBeacon(List beaconList) { 
    for(int i=0; i<beaconList.size(); i++) 
    { 
     Beacon tempBeacon=((Beacon) beaconList.get(i)); 
     if(tempBeacon.getId3() != nearestBeacon.getId3()) 
     { 
      if(tempBeacon.getDistance() < nearestBeacon.getDistance()) 
      { 
       nearestBeacon=tempBeacon; 
      } 
     } 
    } 
    // t1.setText(nearestBeacon.getId2().toString()); 
    Log.d(TAG,"Beacon'ın Majoru: " + nearestBeacon.getId2()); 


} 
} 

私のアプリケーション・コード。

+0

私は別のフォーラムのスレッドから、あなたの質問が特にAndroidビーコンライブラリに関するものであることを知っています。だからあなたの質問にはおそらくそう言わなければなりません。そのログ行は間違っていることを示すものではありませんので、より多くの情報が必要です。 Locateのような棚のトランスミッタでビーコンを検出できますか? https://play.google.com/store/apps/details?id=com.radiusnetworks.locate&hl=en – davidgyoung

+0

ビーコンを検出するアプリケーションを送信しましたが、アプリケーションに表示されません。 –

+0

http://i.hizliresim.com/QvZA1Z.pngが検出されました。 –

答えて

0

は、私はあなたのアプリケーションのために間違っている何が起こっているかわからないけど、Androidの6のスキャンのために、それはすることが重要です:

  • Bluetoothは
  • 場所に権限付与され
  • 場所にあります

iBeaconsをスキャンしていますか?その場合、このライブラリを試すことができます:https://github.com/inthepocket/ibeacon-scanner-androidあなたはもっと運があるかどうかを確認してください。

関連する問題