我必须像facebook一样使用任何网址中的图片.但我无法理解android中的可能性.以及如何在我的应用程序中迁移.我展示一个iOS问题和答案,使用Facebook图形API从网址获取信息,请看这个链接的Facebook图API,所以请帮我解决这个问题.
看下面的图像我想在android中那样
经过长时间的研究,我得到了答案.那我必须在我的项目中使用JSOUP.jar文件和impliment.可以在HTML中解析,我们可以使用html中的细节,现在我想要图像,标题和描述,所以我将从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{ 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(); } } }
我的XML文件用于查看所有数据如下: