Android: How to get or get a specific image from any url or link, like facebook?

I need to use an image from any url like facebook does. But I can not understand how this is possible in Android. and how can I do the migration in my application. I am showing one iOS question and answer that uses facebook graph api to get information from a url, see this link for facebook API, so please help me with this question.

see below image i want like in android enter image description here

+6
source share
2 answers

Finally, I got an answer after lengthy research. This is for me to use the JSOUP.jar file and impliment in my project. which can be parsed in HTML and we can use to drill down from html, Now I want an image, title and description, so I 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 to view all the data is as follows:

 <?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> 
+7
source

This can be obtained by extracting the favicon of the website. Google provided one URL , passing the domain to the request, it will receive an image.

Another option is to get it directly from the website by adding favicon.ico to the domain name

Also, as you gave the Skype example, it extracts a preview of the URL that you are passing, not any specific image.

 (domain/favicon.ico) 
0
source

All Articles