开发者

Connecting to internet thru my app

开发者 https://www.devze.com 2022-12-26 13:57 出处:网络
Is there any way to start the internet through Wifi/GPRS/EDGE/UMTS from application?? Thanks an开发者_C百科d Regards.Basically, you can just assume there\'s an internet connection available, and use

Is there any way to start the internet through Wifi/GPRS/EDGE/UMTS from application??

Thanks an开发者_C百科d Regards.


Basically, you can just assume there's an internet connection available, and use anything that would access the internet (socket, HttpClient, etc). You just need to include error handling in case the device can't get a connection for whatever reason.


If you just want to launch a web browser with a URL use the following:

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));

Of course you need to add the INTERNET permission into your manifest as Rpond suggested:

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


This is a vague question. You can use a WebView to hit a url, or use the built-in Apache HttpClient classes to make any kind of HTTP request. You just need to have the INTERNET permission. And also you can use Intents if you want to launch the browser to view a certain URI.


You don't "start" internet access from within your application. When a user runs your application there can be 2 cases:

  1. Internet is not available

  2. Internet is available. For most cases you don't need to care if its available through GPRS, 3G, wifi, etc. This can have another 2 cases:

    a. Internet is available but for some reason it your requests are timing out.

    b. Internet is available and everything works fine for you.

Your app should be able to handle all these cases and show UI to the user accordingly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号