Use multiple network interfaces in an app

前端 未结 3 651
灰色年华
灰色年华 2021-02-19 13:04

I wrote an app that is triggering a Sony qx smartphone attachable camera over wifi. However I need to transfer the images off the phone over another local network in real time.

相关标签:
3条回答
  • 2021-02-19 13:25

    Most of android tv boxes can use wifi and ethernet together. In my device, i can enable ethernet from this path --- Settings -> More ... > Ethernet --- But your device wont have a menu like that as i understand. So you should make an app to do that. This application needs to access some system specific resources so your device needs to be rooted or application needs to signed with system signature. Also this topic can help you link

    0 讨论(0)
  • 2021-02-19 13:29

    Since you were programming in Nexus 6P, you can try to use the new API added in ConnectivityManager to select the ethernet as your preferred network connection for your process.

    Since I can't build the similar environment like yours, I am not sure if it works. It's just a suggested solution, totally not tested and verified.

    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    Network etherNetwork = null;
    for (Network network : connectivityManager.getAllNetworks()) {
        NetworkInfo networkInfo = connectivityManager.getNetworkInfo(network);
        if (networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
            etherNetwork = network;
        }
    }
    Network boundNetwork = connectivityManager.getBoundNetworkForProcess();
    if (boundNetwork != null) {
        NetworkInfo boundNetworkInfo = connectivityManager.getNetworkInfo(boundNetwork);
        if (boundNetworkInfo.getType() != ConnectivityManager.TYPE_ETHERNET) {
            if (etherNetwork != null) {
                connectivityManager.bindProcessToNetwork(etherNetwork);
            }
        }
    }
    
    0 讨论(0)
  • 2021-02-19 13:46

    Just to give a little more explanation on how this finally got solved.

    Utilizing @alijandro's answer I was able to switch back and forth between Ethernet and Wi-Fi in one app. For some reason for the Ethernet to work it required the network gateway to supply DHCP address, not static. Then since the bindProcessToNetwork, used in @alijandro's answer is per-process, I decided to split communications with the QX camera into a Service that runs in a separate Process. The main Application (another process) would post images over Ethernet to a local network. I was successfully able to contact the devices on the local network via HTTP over Ethernet while simultaneously triggering the QX over Wi-Fi. Currently, I used Messenger to communicate using IPC to tell the QX triggering Service what methods to call.

    0 讨论(0)
提交回复
热议问题