How can I use a 3G internet connection in my Android App?

筅森魡賤 提交于 2019-12-23 09:33:55

问题


I have made an App that can connect to a program that I am running on a server, but it only seems to work with WiFi. When I try to use 3G it doesn't make the connection. Is there something special that I have to turn on or set in order to use 3G?


回答1:


At the application level you (normally) don't have to worry about what data connection is available to the phone.

Have you looked into problems such as when you use WiFi you web server is accessible since you are hitting it from within your network. Whereas, it may not be accessible at all from the public internet which is how the 3G connection will be trying to connect to the server.

What error / exception do you get on 3G?




回答2:


The problem was the port I was using. I was using 4444, but it turns out that many networks block that port. Port 1024 seems to work for most.




回答3:


For what it's worth I was having the same exact problem. My app would work perfect over WiFi but not over 3G. I am on Verizon. I was also using port 4444 because I thought it was a "random" port I had chosen. Thanks to Verizon Wireless blocking this port I spent over an hour trying to diagnose my error. I switched to port 444 and it works fine now. Very frustrating. Hopefully this will help someone else.




回答4:


There shouldn't be anything additional between Wifi, and 3G. All I've included in my Manifest Permissions is android.permission.INTERNET, and that works fine with either Wifi or 3G, so assuming INTERNET is required for Wifi as well (which I'm not entirely sure about, since I haven't tried JUST Wifi) and you've already included it, I don't know of anything else.

If by some chance Wifi does NOT require INTERNET, and it happens to work without it, the Manifest should include a line like:

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

which should grant internet (and 3G) access for your phone. Sorry if that doesn't answer the question, but I can't think of any other reason 3G would be an issue when Wifi works fine. Additionally, make sure you can access the network from another outside location--as said before me, it may be a matter of security preventing outside access somehow. (Not sure what you're using 3G to connect to)




回答5:


The exception that is getting thrown when the socket is made is an IOException, and the timeout (4000) gets reached. When the phone is in Wi-Fi it works fine but when it uses 3G the socket cannot connect to the host/port.




回答6:


You'll have to check with your phone company (and good luck in finding someone who can answer!!) that the 3G network doesn't block ports that you're expecting to be open (and are when in WiFi mode). Some telcos block almost everything you'd expect (and your app stack assumes to be available) to be standard on 3G nets (ping, telnet, RDP etc., etc.).



来源:https://stackoverflow.com/questions/2827143/how-can-i-use-a-3g-internet-connection-in-my-android-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!