Connecting to internet thru my app
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:
Internet is not available
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.
精彩评论