How can ImageView link to web page? - android

is it possible to make an imageview link to a web page such that when user taps on the image, it takes them to a web page?

Just add a click listener to the image to open an URL:
ImageView img = (ImageView)findViewById(R.id.foo_bar);
img.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse("http://casidiablo.net"));
startActivity(intent);
}
});

That's truly possible, at onClick handler you need to start an activity with intent specifying the uri. See How to open default browser for example.

another method we can even use is
image.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent redirect2=new Intent(getApplicationContext(),RedirectAct.class);
startActivity(redirect2);
}
});

Related

access intent to subtitles

I'm trying to access the subtitle settings, so I can change them.
But I'm not managing to find a way to access these settings.
Some advice?
You can use an Intent object like this to open Caption Settings:
NOTE: Minimum API level is 19
Intent intent = new Intent(Settings.ACTION_CAPTIONING_SETTINGS);
startActivity(intent);
For example, if you have a button to open Caption Settings on click.
Button button = (Button) findViewById(R.id.btn);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Settings.ACTION_CAPTIONING_SETTINGS);
startActivity(intent);
}
});
You can return by pressing back button on device.

how to use photo taken by the application?

I have an Android application, which takes a photo if you hit a button:
#Override
public void onClick(View view) {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
view.getContext().startActivity(intent);
}
How can I use the picture and load it into an existing ImageView? (It should overwrite the default picture)
Thank you for your help :)

Is there a way to get information from the web browser in Android?

I would like to create a charity application where if the users were to press the 'Donate' button, their browser would open up a link to a 3rd-party crowdfunding website where they would donate some amount for that project (or choose to exit the app or whatever!). How do I get to know what amount they have donated (or not!) from the browser so that this data can be used for that member's stats, etc.
Yes it is possible. You can use webView
Button button = (Button) findViewById(R.id.b);
button.setOnClickListener(new View.OnClickLister()
#overide
public void onClick(View v) {
WebView mWebView=(WebView)_findViewById(R.id.webView);
mWebview .loadUrl("url for third party app");
setContentView(mWebview );
});
or you can use intent
Button button = (Button) findViewById(R.id.b);
button.setOnClickListener(new View.OnClickLister()
#overide
public void onClick(View v) {
WString url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
});

android show image in default gallery viewer

I am loading some images into my activity using an AsyncTask as clickable images. On click I need to open that image in the default image viewer of the android. I am new to android. Can any one please help. My code looks like
ImageView image = new ImageView(this);
String ed="http://www.domain.com/image.jpg";
image.setTag(ed);
DownloadImagesTask td=new DownloadImagesTask(this);
td.execute(image);
image.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Log.v("TAGG","sdsd");
}
});
Please help me.
Gallery application does not accept URL for an image as part of the Intent. You need to save the image first. Then you can launch the default image viewer with something like this:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + "/sdcard/test.jpg"), "image/*");
startActivity(intent);

Android: Image button as a hyperlink, phone call, map directions?

I have a simple app that I'm putting together for my company. I have 4 buttons that I've created but can't seem to get them to link correctly. One button should open our mobile site, another button to call us, another button to map to us, and the final button linked to our "News" site. Any help would be greatly appreciated!
On your buttons, you should set OnClickListener, and to do some required actions you could see the example below:
To Open a Map with Certain Location
mapButton.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=" + your-location-geo-address));
startActivity(i);
}
});
To call certain number
callButton.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + telephone-number));
startActivity(i);
}
});
To open a website
linkButton.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(website-address));
startActivity(i);
}
});
Change "location-address", "telephone-number", and "website-address" with your own String value.
I hope this helps.
anmustangs answer is very good, but one thing I would like to add for the button you are making for a link to your site, where anmustangs wrote (website-address) instead of just typing in a site, it needs to put formatted correctly. For example, you can use "http://www.google.com" and yes you do need to use the quotation marks I put in there. I know I am years late to this thread but who knows who my post may help.

Categories

Resources