2016-12-09 2 views
0

Ich habe Android 6.0 Telefon. Diese App sieht den Beacon nicht. I am getting this errorAndroid 6.0 nicht sehen Beacon

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

Können Sie mir helfen?

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()); 


} 
} 

Meine Anwendungscodes.

+0

Ich weiß aus einem Thread in einem anderen Forum, dass Ihre Frage speziell über die Android Beacon Library ist, also sollten Sie es wahrscheinlich in Ihrer Frage sagen. Diese Protokollzeile zeigt nicht an, dass etwas falsch ist. Daher benötigen wir weitere Informationen, um Ihnen zu helfen. Können Sie den Beacon mit einem handelsüblichen Sender wie Locate erkennen? https://play.google.com/store/apps/details?id=com.radiusnetworks.locate&hl=en – davidgyoung

+0

Sie senden in der Anwendung, die Beacons erkennt, aber meine Anwendung nicht sehen. –

+0

http://i.hizliresim.com/QvZA1Z.png erkannt. –

Antwort

0

Ich bin nicht sicher, was für Ihre Anwendung nicht in Ordnung ist, aber für das Scannen auf Android 6, ist es wichtig, dass:

  • bluetooth auf
  • Lage ist, auf
  • Standort Erlaubnis erteilt

Suchen Sie nach iBeacons? In diesem Fall können Sie diese Bibliothek ausprobieren: https://github.com/inthepocket/ibeacon-scanner-android, um zu sehen, ob Sie mehr Glück haben.

Verwandte Themen