Ble de numérisation de rappel seulement appelée à plusieurs reprises, puis arrêté

J'ai 2 téléphones avec Android 5.0.2, ils ont tous les deux installé le dernier Rayon Phare de l'App: Recherchez Phare, en attendant, je me suis tourné sur 2 IBeacon de l'expéditeur, et vous pourrez voir les RSSI changer à la fois au téléphone avec l'Application.

Mais quand j'ai essayé d'écrire un exemple de code pour simuler situation ci-dessus, j'ai trouvé le ble d'analyse de rappel toujours arrêter appelée ci-après appelé 2 ou 3 fois, j'ai d'abord soupçonner la "Localiser le Phare" peuvent utiliser différentes, alors je l'ai essayé avec 2 types d'API, l'un est pour les vieux 4.4, et l'autre est la nouvelle façon introduite dans android 5, mais les deux le même comportement(mais le tout fonctionnant sur android 5).

l'4.4:

public class MainActivity extends Activity {
private BluetoothAdapter mBluetoothAdapter;
private static final String LOG_TAG = "BleCollector";
private TextView calledTimesTextView = null;
private int calledTimes = 0;
//Device scan callback.
private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(final BluetoothDevice device, int rssi,
byte[] scanRecord) {
calledTimes++;
runOnUiThread(new Runnable() {
@Override
public void run() {
calledTimesTextView.setText(Integer.toString(calledTimes));
}
});
Log.e(LOG_TAG, "in onScanResult, " + " is coming...");
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
calledTimesTextView = (TextView) findViewById(R.id.CalledTimes);
mBluetoothAdapter = ((BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE))
.getAdapter();
mBluetoothAdapter.startLeScan(mLeScanCallback);
}
@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
public boolean onOptionsItemSelected(MenuItem item) {
//Handle action bar item clicks here. The action bar will
//automatically handle clicks on the Home/Up button, so long
//as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}}

Et la 5.0.2:

public class MainActivity extends Activity {
private BluetoothAdapter mBluetoothAdapter = null;
private BluetoothLeScanner mLescanner;
private ScanCallback mLeScanCallback;
private static final String LOG_TAG = "BleFingerprintCollector";
private TextView calledTimesTextView = null;
private int calledTimes = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
calledTimesTextView = (TextView) findViewById(R.id.CalledTimes);
this.mBluetoothAdapter = ((BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE))
.getAdapter();
this.mLescanner = this.mBluetoothAdapter.getBluetoothLeScanner();
ScanSettings bleScanSettings = new ScanSettings.Builder().setScanMode(
ScanSettings.SCAN_MODE_LOW_LATENCY).build();
this.mLeScanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
calledTimes++;
runOnUiThread(new Runnable() {
@Override
public void run() {
calledTimesTextView.setText(Integer
.toString(calledTimes));
}
});
Log.e(LOG_TAG, "in onScanResult, " + " is coming...");
}
@Override
public void onBatchScanResults(List<ScanResult> results) {
}
@Override
public void onScanFailed(int errorCode) {
}
};
this.mLescanner.startScan(null, bleScanSettings, this.mLeScanCallback);
}
@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
public boolean onOptionsItemSelected(MenuItem item) {
//Handle action bar item clicks here. The action bar will
//automatically handle clicks on the Home/Up button, so long
//as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}}

Ils sont très simple et juste montrer un compteur dans l'INTERFACE utilisateur, s'est avéré finalement toujours arrêté à 2 ou 3.

J'ai joué à ce ble de la publicité de la réception avant sur un SamSung note 2 avec android 4.4 appareil, il fonctionne parfaitement, la fonction de rappel appelée à chaque seconde.
alors quelqu'un peut aider? pourquoi Rayon " Localiser le Phare fonctionne bien ici?

OriginalL'auteur Shawn | 2015-04-19