简体   繁体   English

强制第三方应用的Wi-Fi网络

[英]Force Wi-Fi network for 3rd party apps

I have an Android app and a server available through Wi-Fi. 我有一个Android应用程序和一个可通过Wi-Fi服务器。
For some operations (eg video streaming from the server) my app uses third-party apps by sharing the URL of the file. 对于某些操作(例如来自服务器的视频流),我的应用程序通过共享文件的URL来使用第三方应用程序。

Starting from Android L device can be connected to both Wi-Fi and cellular simultaneously, which breaks my app since the server doesn't have Internet and cellular network is getting preferred by Android (since it has Internet), so URL cannot be resolved. 从Android L设备开始可以同时连接到Wi-Fi和蜂窝网络,这打破了我的应用程序,因为服务器没有互联网,而且蜂窝网络越来越受到Android的青睐(因为它有互联网),因此URL无法解析。 I fixed this by binding my app to Wi-Fi with bindProcessToNetwork() . 我通过bindProcessToNetwork()将我的应用程序绑定到Wi-Fi来修复此问题。 But when the app shares the URL with 3'rd-party app, the URL still cannot be resolved since 3'rd-party app is not bind to Wi-Fi. 但是,当应用程序与第三方应用程序共享URL时,由于第三方应用程序未绑定到Wi-Fi,因此仍无法解析该URL。

Is there a way to let 3'rd party app use Wi-Fi instead of cellular while opening the URL my app provided? 有没有办法让第三方应用程序在打开我的应用程序提供的URL时使用Wi-Fi而不是蜂窝?

在此输入图像描述

Here you have an explanation on how to force a type of network to a specific address: 在这里,您可以解释如何将某种类型的网络强制到特定地址:

How to use 3G Connection in Android Application instead of Wi-fi? 如何在Android应用程序中使用3G连接而不是Wi-Fi?

If you know the URL of the 3rd party services you can try it. 如果您知道第三方服务的URL,则可以尝试使用它。 Remember that the code relies on network so it should run off the UI thread. 请记住,代码依赖于网络,因此它应该运行UI线程。 Also this code uses some deprecated methods. 此代码也使用了一些不推荐使用的方法。

There are many many ways to achieve that ... first off the top of my head is create aa vpn app that captures all traffic flowing into and out of the device and re-rout as appropriate, so even if your 3rd party app thinks its using cellular its actual tcp packets can be coming from somewhere completely different, even bluetooth if you want to. 有许多方法可以实现这一目标......首先,我要创建一个vpn应用程序,捕获流入和流出设备的所有流量,并根据需要重新进行重新路由,即使您的第三方应用程序认为其使用蜂窝,它的实际tcp数据包可以来自某个完全不同的地方,如果你愿意,甚至可以使用蓝牙。

Second, quick and dirty (not sure, havent tried that but a quick google search threw that my way) , go to your data usage, enable data cutoffs (the red and orange lines) doesnt matter what you set them to but they have to be enabled. 第二,快速和肮脏(不确定,没有尝试过,但快速谷歌搜索扔我的方式),转到您的数据使用,启用数据截止(红色和橙色线)无关紧要你设置他们但他们必须被启用。 Next scroll down you will find a list of apps using data, find your 3rd party app, you'll find another checkbox to limit its background data,mark it. 接下来向下滚动,您将找到使用数据的应用列表,找到您的第三方应用,您将找到另一个复选框来限制其背景数据,标记它。 Now this 3rd party app can no longer use mobile data without your consent: only actions you triggered yourself ("foreground data") will be performed by it, no sync in the background or other background activity. 现在,这个第三方应用程序无法在未经您同意的情况下使用移动数据:只有您自己触发的操作(“前景数据”)才会执行,后台或其他后台活动无法同步。 So if YOUR app shares the URL internally with the 3rd Party app and no ui is involved, then that should work 因此,如果你的应用程序在内部与第三方应用程序共享URL并且没有涉及到ui,那么这应该可行

if you just copy and paste the URL manually, then while your at it manually turn of mobile data. 如果您只是手动复制并粘贴网址,那么当您手动转动移动数据时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM