2017-01-15 1 views
0

J'ai un problème avec la bibliothèque Beacon Android AltBeacon, j'ai mis toutes les permissions (BLUETOOTH, BLUETOOTH_ADMIN, ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION), mais mon application pour certaines raisons ne peut pas détecter de balises (essayé avec peu différent). J'utilise Samsung Galaxy Tab avec android 6.0.1. Alors que je lance mon application, je reçois ce message: Android 6.0.1 API 23 - Bibliothèque Beacon ne fonctionne pas

I/BeaconActivity: I have just switched from seeing/not seeing beacons: 0 
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 48 - 0, 0) vi=Rect(0, 48 - 0,  0) or=1 
D/libGLESv1: STS_GLApi : DTS is not allowed for Package : com.example.tgesior.beacons 
D/BluetoothAdapter: STATE_ON 
D/BluetoothAdapter: STATE_ON 
D/BluetoothLeScanner: Start Scan 
D/BluetoothAdapter: STATE_ON 
D/BluetoothAdapter: STATE_ON 
D/BluetoothAdapter: STATE_ON 
D/BluetoothAdapter: STATE_ON 
I/Timeline: Timeline: Activity_idle id: [email protected] time:32794199 
D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7 
D/ScanRecord: parseFromBytes 
D/ScanRecord: first manudata for manu ID 
D/ScanRecord: parseFromBytes 
D/ScanRecord: first manudata for manu ID 
D/ScanRecord: parseFromBytes 
D/ScanRecord: first manudata for manu ID 
D/ScanRecord: parseFromBytes 
D/ScanRecord: first manudata for manu ID 
D/ScanRecord: parseFromBytes 
D/ScanRecord: first manudata for manu ID 
D/ScanRecord: parseFromBytes 
D/ScanRecord: first manudata for manu ID 
D/ScanRecord: parseFromBytes 
D/ScanRecord: first manudata for manu ID 
D/ScanRecord: parseFromBytes 
D/ScanRecord: first manudata for manu ID 
D/ScanRecord: parseFromBytes 
D/ScanRecord: first manudata for manu ID 
D/ScanRecord: parseFromBytes 
D/ScanRecord: first manudata for manu ID 
D/ScanRecord: parseFromBytes 
D/ScanRecord: first manudata for manu ID 
D/ScanRecord: parseFromBytes 
D/ScanRecord: first manudata for manu ID 
D/ScanRecord: parseFromBytes 
D/ScanRecord: first manudata for manu ID 
D/ScanRecord: parseFromBytes 
D/ScanRecord: first manudata for manu ID 
D/ScanRecord: parseFromBytes 
D/ScanRecord: first manudata for manu ID 
D/BluetoothAdapter: STATE_ON 
D/BluetoothAdapter: STATE_ON 
D/BluetoothLeScanner: Stop Scan 
D/BluetoothLeScanner: Start Scan 
D/BluetoothAdapter: STATE_ON 
D/BluetoothAdapter: STATE_ON 
D/BluetoothAdapter: STATE_ON 
D/BluetoothAdapter: STATE_ON 
D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7 

et ainsi de suite, voici mon code:

private BeaconManager beaconManager =null; 

private static final String ALTBEACON_LAYOUT = "m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"; 

private static final int PERMISSION_REQUEST_COARSE_LOCATION = 1; 


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

    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 access"); 
      builder.setMessage("Please grant location access so this app can detect beacons."); 
      builder.setPositiveButton(android.R.string.ok, null); 
      builder.setOnDismissListener(new DialogInterface.OnDismissListener() { 
       @Override 
       public void onDismiss(DialogInterface dialog) { 
        requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_REQUEST_COARSE_LOCATION); 
       } 
      }); 
      builder.show(); 
     } 
    } 

    beaconManager = BeaconManager.getInstanceForApplication(this); 
    beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout(ALTBEACON_LAYOUT)); 
    beaconManager.setForegroundScanPeriod(30000l); 
    beaconManager.setForegroundBetweenScanPeriod(21000l); 

    beaconManager.bind(this); 

} 

public void onRequestPermissionsResult(int requestCode, 
             String permissions[], 
             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 
public void onBeaconServiceConnect() { 
    beaconManager.addMonitorNotifier(new MonitorNotifier() { 
     @Override 
     public void didEnterRegion(Region region) { 
      Log.i(TAG, "I just saw an beacon for the first time!"); 
     } 

     @Override 
     public void didExitRegion(Region region) { 
      Log.i(TAG, "I no longer see an beacon"); 
     } 

     @Override 
     public void didDetermineStateForRegion(int state, Region region) { 
      Log.i(TAG, "I have just switched from seeing/not seeing beacons: "+state); 
     } 
    }); 

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

+0

Ceci est pour alt beacon? – dazza5000

+0

Oui c'est pour les balises alt – drPAYMENT

Répondre