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);
Related
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 :)
This question already has answers here:
How to share a file in Android programmatically
(5 answers)
Closed 5 years ago.
In my app, i am trying to implement Share button, Which when clicked should give me list of all the social media icons. I was looking at some examples, i like the way media is shared on "WhatApp", u selected the media, click on share, the a window slides up from bottom with the list of social media icons, i saw this kind of implemenatation in othe apps also, and you slide left or right to see more icons. How do i implement something like this in my app. Any examples would be appreciated. below is the screen shot of one of the apps.
share.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");// You Can set source type here like video, image text, etc.
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(fileUrl);
shareIntent.setFlags(FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(shareIntent, "Share File Using!"));
}
});
here share is my ImageView
let me know if any query
Firstly set that image on ImageView and then use this code to share the image :-
share.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Uri bmpUri = getLocalBitmapUri(img);
if (bmpUri != null) {
// Construct a ShareIntent with link to image
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
shareIntent.setType("image/*");
// Launch sharing dialog for image
startActivity(Intent.createChooser(shareIntent, "Share Image"));
} else {
// ...sharing failed, handle error
}
}
});
"img" is my image which i want to share.
i have a problem with my app, i tried this code to do a tweet from my app without using the sdk:
ImageView Twitter = (ImageView) findViewById(R.id.imageView4);
Twitter.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("plain/text");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,
"This is the text that will be shared.");
startActivity(Intent.createChooser(sharingIntent,
"Share via"));
}
});
I just wanted to share text+link, but when i press the button, TWITTER DOESNT EXISTS, facebook too don't appear!
Else this two apps, appear: gmail, bluetooth, edmodo, etc..
So, i tried to do it for other way, "beast way" :D
ImageView Twitter = (ImageView) findViewById(R.id.imageView4);
Twitter.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent browserIntent =
new Intent(Intent.ACTION_VIEW,
Uri.parse("https://twitter.com/intent/tweet?text=https://play.google.com/store/apps/details?id=lol.king%20-%20This%20app%20is%20amazing,%20i%20love%20it!"));
startActivity(browserIntent);
}});
If you read carefully the link and try it (in ur computer) you will see the good results, BUT when i do it in my android phone, it give me the chance to run this link with Twitter App(if you dont have it, will go directly to the link and there will be no problem). And of course when i click it, appear an error: "Twitter has stopped"). Can you help me to tweet Links+texts (or if is impossible to share both, just Link?
I'm new at Android apps and I'm working on a project started by a friend of mine. The code below is from a class that loads a view that has a small image with some text around it.
I want the image to appear fullscreen (on the standard Android image viewer) when I click on the thumbnail.
I tried several different solutions, and none of them worked.
This example throws the following exception:
E/AndroidRuntime(13768): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=android.resource://com.app.mid/2130837533 typ=image/png }
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_n1);
ImageView img = (ImageView) findViewById(imageResource);
img.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("android.resource://com.app.mid/" + R.drawable.p_page_11_image_0001), "image/png");
startActivity(intent);
}
});
}
The images are inside the drawable folder (..\res\drawable-xhdpi). I'm using Eclipse ADT and I configured it to run on my Galaxy Nexus.
Again, I tried several solutions with no luck. Any thoughts?
Thanks
Try to use Intent.ACTION_VIEW instead of android.content.Intent.ACTION_VIEW
Intent i = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(yourUri, "image/png");
startActivity(intent);
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);
}
});