Android send data via web page URL

GlobaLevel
GlobaLevel used Ask the Experts™
on
Is there sample code that when a button is click the on click listener will raise an intent to launch an activity to to post data to a web page URL
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

1. Add a button in your layout file with:

android:onClick="onOpenWebBrowser"

Open in new window


2. Import the following packages:

import android.net.Uri;
import android.content.Intent;

Open in new window


3. Add the following code:

    //Opens a web page when a button is clicked
    public void onOpenWebBrowser(View v)
    {
    	Intent webPageIntent = new Intent(Intent.ACTION_VIEW);
    	webPageIntent.setData(Uri.parse("http://www.computeregghead.com"));

    	try { 
    	    startActivity(webPageIntent);
    	} catch (ActivityNotFoundException ex) { 
    	    // do something about the exception 
    	}
    }

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial