0

I am detecting a device on a private network with no internet access. The only devices on the network are the device I'm detecting and the mobile devices or PC's that have app I am currently working on. This words just fine on Android 5.1.1 but on 7, I'm getting no response like its not finding anything. Here is the code I'm using to detect the device. The type I am using is _telnet._tcp. and the Cordova plugin I am using here is cordova-plugin-zeroconf

find(type) {// javascript
    return new Promise((resolve, reject) => {
        cordova.plugins.zeroconf.watch(type, "local.", (result) => {
            var action = result.action;
            var service = result.service;

            if (action == 'added') {
                console.debug('service added', service);
            }
            else if (action == 'resolved') {
                console.debug('service resolved', service);
                resolve({ status: "resolved", service: service });
            }
            else {
                console.debug('service removed', service);
                resolve({ status: "removed", service: service });
            }
        }, (error) => {
            reject(error);
        });
    });
}

I originally thought it might be because of permissions so I added this to the MainActivity in the Cordova Android project. And I can see it logs "has permission".

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {//java
    Log.d(TAG, "version 23 or more");
    if (checkSelfPermission(Manifest.permission.ACCESS_WIFI_STATE) == PackageManager.PERMISSION_GRANTED &&
        checkSelfPermission(Manifest.permission.CHANGE_WIFI_MULTICAST_STATE) == PackageManager.PERMISSION_GRANTED &&
        checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
    Log.d(TAG, "has permission");
}
else {
    Log.d(TAG, "no permission");
    requestPermissions(new String[] { Manifest.permission.ACCESS_WIFI_STATE,
            Manifest.permission.CHANGE_WIFI_MULTICAST_STATE, 
            Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0);
    }
}
Jason Crosby
  • 3,533
  • 4
  • 28
  • 49
  • 1
    I did install a 3rd party browser app on the Android 7 tablet and was able to see the device I'm trying to find. – Jason Crosby Mar 27 '18 at 20:54
  • 1
    I have tried this on 2 Android devices running 7.0 and one running 7.1.1 and they all do not find this device I need to connect to. Were there any changes made to Android starting in 7.0 that makes this not work? – Jason Crosby Apr 02 '18 at 20:12

1 Answers1

0

I ended up redoing the plugin to make use of Android's Network Service Discovery (NSD). I was able to get it to work with that. For the life of me I have no idea why the plugin wouldn't work for me. I never did find out what was causing it to not work.

Jason Crosby
  • 3,533
  • 4
  • 28
  • 49