Hi i have a problem to make scanner


#1

hi i make a android ble scanner by ur sdk

but i face some problem.

because of my scanner can’t scan ur beacon.

i test two kind of ur product first one is AprilBeacon 202 and second one is Bracelet ibeacon.
first one pretty nicely scaned all of beacon(i can scan all of them(4))
but second one can’t scan more than two(i test four beacon also).

and i use another app like ur April Beacon App, it can scan all of them. i thinks i miss something to make a scanner App.

if u have a clue of solve this issue plz help me plz!


#2

Which sdk did you use ?
AprilBeaconSdk or AprilScanSdk


#3

You can set different uuid major and minor to have a try


#4

i thinks i use both of them

compile files('libs/aprilscansdk.jar')
compile files('libs/ab-sdk-beta1.6.7.jar')

n my scan code copy from april beacon demo1


#5

you can try the scansdk and test the scandemo on github


#6

haha i try to find any change with scnademo’s code but i can’t

n it’s same as i used before

n problem is same occur.


#7

package sensview.lost.daosis.safetytracker;

import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import com.aprbrother.aprilbeaconscansdk.Beacon;
import com.aprbrother.aprilbeaconscansdk.ScanManager;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

/**

  • Created by Administrator on 2017-01-31.
    */

public class WhiteList extends AppCompatActivity {
//DB 셋팅
SQLiteDatabase sql;
wlDB wl;

ListView ll;
HashMap map;
Cursor cursor;
ArrayList nameList;
TextView nameView;

Switch macSw;
String selected;

Spinner spinner;
ImageButton back_bnt, save_bnt, delete_bnt;

private BeaconAdapter adapter;
private ScanManager scanManager;
private ArrayList<Beacon> myBeacons = new ArrayList<>();
private ArrayList<String> macList;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.whitelist_setup);

    spinner = (Spinner)findViewById(R.id.spinner);
    wl = new wlDB(this);
    nameView = (TextView)findViewById(R.id.nameView);
    macSw = (Switch) findViewById(R.id.MacAdress);

    map = new HashMap();

    back_bnt =(ImageButton)findViewById(R.id.return_bnt);
    save_bnt =(ImageButton)findViewById(R.id.save_bnt);
    delete_bnt =(ImageButton)findViewById(R.id.delete_bnt);

    //Mashmellow scan permission
    ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION);
    ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION},
            10);

    setShow();

    macSw.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if( macSw.isChecked()){

                startScan();

                macSw.setThumbDrawable(getResources().getDrawable(R.drawable.switch_thumb));


            }else if(!macSw.isChecked()){

                scanManager.stopScan();

                macSw.setThumbDrawable(getResources().getDrawable(R.drawable.switch_off));

            }


        }
    });


    back_bnt.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            finish();
        }
    });

    //저장, 수정
    save_bnt.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {


            sql = wl.getReadableDatabase();


            if(nameView.getText().length()>0){

            if(!map.containsKey(selected)){
                sql.execSQL("insert into list values('"+selected+"','"+nameView.getText()+"');");
            }else if(map.containsKey(selected)){
                //UPDATE table_name SET column1 = value1, column2 = value2...., columnN = valueN WHERE [condition];
                sql.execSQL("update list set name='"+nameView.getText()+"' where mac='"+selected+"';");
            }
            delete_bnt.setVisibility(View.INVISIBLE);
            sql.close();
            setShow();}
        }
    });

    //삭제
    delete_bnt.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            delete_bnt.setVisibility(View.INVISIBLE);
            sql = wl.getReadableDatabase();
            System.out.println("Mac:"+selected+"\t"+map.containsKey(selected));

            sql.execSQL("delete from list where mac like '"+selected+"';");
            sql.close();

            setShow();
        }
    });

}


private void startScan() {
    scanManager = new ScanManager(this);

// scanManager.setUuid(“00000000-0000-0000-0000-000000000000”);//添加需要扫描的uuid 只有符合的才会返回 不设置返回所有
// scanManager.setMajor(222);//添加需要扫描的beacon的major 只有符合的major才会返回 不设置返回所有
// scanManager.setMinor(111);//添加需要扫描的beacon的minor 只有符合的minor才会返回 不设置返回所有
// scanManager.setScanPeriod(1000);//设置beacon扫描 反馈结果时间间隔 时间越久 扫描丢失率越低 默认3000ms
scanManager.startScan();//启动扫描
// scanManager.stopScan();//停止扫描
// scanManager.setScanListener(new ScanManager.MyScanListener());//设置扫描监听 监听扫描返回数据
scanManager.setScanListener(new ScanManager.MyScanListener() {
@Override
public void onScanListenre(ArrayList beacons) {
Log.i(“list”, "------------------------------beacons.size = " + beacons.size());
myBeacons.clear();
myBeacons.addAll(beacons);
ComparatorBeaconByRssi com = new ComparatorBeaconByRssi();
Collections.sort(myBeacons, com);

           // adapter.replaceWith(myBeacons);

          /* if(myBeacons.size()==beacons.size()){
                    scanManager.stopScan();
                    macSw.setChecked(false);
                    macSw.setThumbDrawable(getResources().getDrawable(R.drawable.switch_off));

                }*/

            setBeacons(myBeacons);
        }
    });
}


 //리스트 생성
public void setShow(){

   sql = wl.getReadableDatabase();
   nameList = new ArrayList<>();
   cursor = sql.rawQuery("SELECT * FROM LIST;", null);
   macList = new ArrayList<>();
    if(cursor.getCount()>0) {

        nameList.clear();

        while (cursor.moveToNext()) {

            nameList.add("Mac Adress : " + cursor.getString(0) + "\n\tUser Name : " + cursor.getString(1));

            map.put(cursor.getString(0), cursor.getString(1));

            macList.add(cursor.getString(0));
            macList.add(cursor.getString(1));
        }

        ll = (ListView) findViewById(R.id.ListMac);


        ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, nameList);

        ll.setAdapter(adapter);

        adapter.notifyDataSetChanged();

        if(nameList.size()<1){

            adapter.clear();
        }

        ll.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                System.out.println("======================position:"+position);
              if(position==0){
               selected = macList.get(0);
                  nameView.setText(macList.get(1));
              }else{
                  selected = macList.get(position * 2);
                  nameView.setText(macList.get(position * 2 + 1));
              }
                delete_bnt.setVisibility(View.VISIBLE);
            }
        });

    }
    sql.close();

}

  //리스트 생성
public void setBeacons(final ArrayList<Beacon> beaconses){

    final ArrayList<String> nameList = new ArrayList<>();

    nameList.clear();

    for(Beacon beacon:beaconses){

           // nameList.add(beacon.getMacAddress());
       if(!map.containsKey(beacon.getMacAddress())){
            nameList.add(beacon.getMacAddress());}

    }

    ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, nameList);

    spinner.setAdapter(adapter);

    adapter.notifyDataSetChanged();


     spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
         @Override
         public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
             selected = nameList.get(position);
             nameView.setText(beaconses.get(position).getName());

         }

         @Override
         public void onNothingSelected(AdapterView<?> parent) {

         }
     });




}

#8

here is my code n it still find all of beacon 202 but it can’t find bended one more than two


#9

Try to set different uuid major minor
And Try set adv small then 1s