i have to use image from any url as like facebook does. But i can't understood to how it possible in android. and how can i migrate in my application. i show one iOS question and answer that uses facebook graph api for get information from url, see this link for facebook graph API, so please help me for this question solution.
Asked
Active
Viewed 2,354 times
8
-
where do you want to display image – Sameer Donga Dec 25 '15 at 04:46
-
in custom listview with image and text – Ravi Vaghela Dec 25 '15 at 04:56
-
use picasso lib. here is the link http://square.github.io/picasso/ . this will display images from url and also handle error by itself. – Sameer Donga Dec 25 '15 at 04:59
-
@SameerDonga picaso library use for only link base image not get image from any link like i will use www.google.com, www.facebook.com, that link from get to image of perticuller link. – Ravi Vaghela Dec 25 '15 at 05:04
-
see my question update with image.. – Ravi Vaghela Dec 25 '15 at 05:09
-
@RaviVGHL Make a custom Adapter and a getter setter class for showing the images in your listview – Chaudhary Amar Dec 25 '15 at 06:40
2 Answers
9
Finally I got answer after long research. That for i have to use JSOUP.jar file and impliment in my project. that can be parse in HTML and we can use to detail from html, Now i want image, title and description so i will get from HTML.
public class MainActivity extends Activity {
Document document;
String url ;
ProgressDialog mProgressDialog;
TextView t1, t2;
ImageView img;
String title, desc, img_url;
Button btn;
EditText et;
Bitmap bitmap;
String UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img = (ImageView) findViewById(R.id.imgIcon);
t1 = (TextView) findViewById(R.id.txtTitle);
t2 = (TextView) findViewById(R.id.txtDesc);
btn = (Button) findViewById(R.id.button);
et = (EditText) findViewById(R.id.editText);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
url = et.getText().toString();
new FetchWebsiteData().execute();
}
});
}
private class FetchWebsiteData extends AsyncTask<Void, Void, Void> {
String websiteTitle, websiteDescription, imgurl;
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(MainActivity.this);
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
try {
// Connect to website
Document document = Jsoup.connect(url).userAgent(UserAgent).get();
// Get the html document title
websiteTitle = document.title();
Elements description = document.select("meta[name=description]");
// Locate the content attribute
websiteDescription = description.attr("content");
String ogImage = null;
Elements metaOgImage = document.select("meta[property=og:image]");
if (metaOgImage != null) {
imgurl = metaOgImage.first().attr("content");
System.out.println("src :<<<------>>> " + ogImage);
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
t1.setText(websiteTitle + "------" + imgurl);
t2.setText(websiteDescription);
Picasso.with(getApplicationContext()).load(imgurl).into(img);
mProgressDialog.dismiss();
}
}
}
And my XML file for view all data is following:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.copy.urlparsing.MainActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imgIcon"
android:src="@drawable/asf"
android:layout_alignBottom="@+id/txtDesc"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/txtTitle"
android:layout_above="@+id/imgIcon"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/txtDesc"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="53dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:layout_below="@+id/editText"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>

Ravi Vaghela
- 3,420
- 2
- 23
- 51
0
This you can get by fetching favicon of the website. Google provided one URL, passing domain into query it will fetch image.
The other option is to get it directly from website appending favicon.ico in domain name
Also as you gave the example of Skype, it is fetching preview of url you pass, not any particular image.
(domain/favicon.ico)

Community
- 1
- 1

Arth Tilva
- 2,496
- 22
- 40