Code Monkey home page Code Monkey logo

Comments (8)

philips77 avatar philips77 commented on June 4, 2024

On Marshmallow+ you have to request Location permission (coarse or fine). It enable it in settings->apps->your app->permissions->location. Please read about new permission scheme on Android 6.

from android-scanner-compat-library.

Jai-GAY avatar Jai-GAY commented on June 4, 2024

May be you have to take a look at the scanner handler you have acquired ?

instead of getting it from the BluetoothAdapter, acquire the scanner instance using:
BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat.getScanner();
You also need to change the packets for ScanSettings, ScanFilter and ScanCallback classes to:
no.nordicsemi.android.support.v18.scanner

hope it helps.

from android-scanner-compat-library.

DLeague9 avatar DLeague9 commented on June 4, 2024

i added
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
in manifest. Nothing worked.
i'm not using BluetoothAdapter. Is that an issue?
My scan method below:

private void EstablishConnection(){
        BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat.getScanner();
        scanner.startScan(mScanCallback);
    }

Callback methods:

private final no.nordicsemi.android.support.v18.scanner.ScanCallback mScanCallback = new no.nordicsemi.android.support.v18.scanner.ScanCallback() {
        @Override
        public void onScanResult(int callbackType, no.nordicsemi.android.support.v18.scanner.ScanResult result) {
            if (result!=null) {
                BluetoothDevice device = result.getDevice();
                if("BLE_PRO".equals(device.getName())){
                    Log.i("DeviceFound: ", device.getAddress());
                    BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat.getScanner();
                    scanner.stopScan(mScanCallback);
                    connect(device);
                }
            }
        }

        @Override
        public void onBatchScanResults(List<no.nordicsemi.android.support.v18.scanner.ScanResult> results) {
            //for batch scan result
        }

        @Override
        public void onScanFailed(int errorCode) {
            // Scan error
        }
    };

from android-scanner-compat-library.

philips77 avatar philips77 commented on June 4, 2024

Setting in the manifest is not enough: https://developer.android.com/training/permissions/requesting.html

from android-scanner-compat-library.

Jai-GAY avatar Jai-GAY commented on June 4, 2024

i think i encounter unstable / unexpected result if i call scanner.stopScan(mScanCallback); inside the callback.

i suggest do not do that and the scan result should be inside onBatchScanResults callback and not onScanResult. try do some Log.d (); print out to diagnose. and the activities inside the callbacks should return as soon as possible, so no heavy / lengthy API calling.

@OverRide
public void onBatchScanResults(List results)
{
super.onBatchScanResults(results);
if (results.size() > 0)
{}
}

hope it helps.

from android-scanner-compat-library.

DLeague9 avatar DLeague9 commented on June 4, 2024

I solved it by getting permission dynamically

private boolean checkPermission() {
        int result = this.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION);
        if (result == PackageManager.PERMISSION_GRANTED) {
            return true;
        } else {
            return false;
        }
    }

  private void requestPermission() {
        if (ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.ACCESS_FINE_LOCATION)) {
            Snackbar.make(findViewById(android.R.id.content), "GPS permission allows us to access location data. Please allow in App Settings for additional functionality.", Snackbar.LENGTH_LONG).show();
        } else {
            ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSION_REQUEST_CODE);
        }
    }
```

Thanks for help.

from android-scanner-compat-library.

Jai-GAY avatar Jai-GAY commented on June 4, 2024

interesting why you didn't hit this exception in the first place ?

from android-scanner-compat-library.

philips77 avatar philips77 commented on June 4, 2024

I guess it depends on the phone you are using... They log different things.

from android-scanner-compat-library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.