MobileChromeApps / cordova-plugin-chrome-apps-sockets-udp

BSD 3-Clause "New" or "Revised" License
80 stars 40 forks source link

Permission denied to sendBroadcast #16

Closed janoelker closed 7 years ago

janoelker commented 7 years ago

I am using this plugin with several android apps. Just for my Nexus 5x with Android 7 it isn't working. I get the following error:

Permission denied
callbackWithError @ errors.js:31
fail @ sockets.udp.js:75
cordova.callbackFromNative @ cordova.js:295
processMessage @ cordova.js:1081
processMessages @ cordova.js:1104
pollOnce @ cordova.js:973
pollOnceFromOnlineEvent @ cordova.js:960

The error is thrown while I am trying to send a broadcast. This is how my code basically looks like:

function sendBroadcast(data) {
    chrome.sockets.udp.create(function (createInfo) {
        udpSocketId = createInfo.socketId;

        chrome.sockets.udp.setBroadcast(udpSocketId, false, function (result) {
            if (result < 0) {
                console.log("setBroadcast failed");
            }
        });

        chrome.sockets.udp.bind(udpSocketId, '0.0.0.0', udpPORT, function (result) {
            chrome.sockets.udp.send(udpSocketId, data, '255.255.255.255', udpPORT, function (result) {
                if (result < 0) {
                    console.log("sendBroadcast failed");
                } 
            });
        });
    });
}

As I said, for the other android systems this is working perfectly fine. I checked the AndroidManifest.xml and the INTERNET permission param is set. Furthermore, I checked all permission in the android apps settings. All permissions are set on true. Meanwhile, I started a listener, which receives other broadcasts. This confuses me, because it shows that the permission is set. Also, I am sure that no broadcasts are send, because my server doesn't receive any.

While debugging I found this:

F09 ChromeSocketsUdp557920677 {"message":"Permission denied","resultCode":-2}

Maybe this part contains some information for you guys.

I am not sure where the problem is coming from.

gregvis commented 7 years ago

You have setBroadcast set to false in your code. Set it to true instead.

setBroadcast(udpSocketId, true, ....

janoelker commented 7 years ago

Ok, that was it. Sorry for stealing your time.