我想使用intent从图像的另一个url打开图像的url。我是android的新手,所以我的这段代码不起作用。
url_1 = new URL("http://garooh.905pm.com"+com.org.constant.Helper.Gadd_list.get(0).thisEvent.getImage_four_thumb());
url_2 = new URL("http://garooh.905pm.com"+ com.org.constant.Helper.Gadd_list.get(0).thisEvent.getImage_four_thumb());
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(url_1, url_2);
startActivity(intent);
答案 0 :(得分:0)
我认为您有一个图像按钮是正确的,当您点击它时,您想要转到其中一个网址吗?
尝试将此添加到您的imageButton。
imageButton.setOnClickListener(new locatorButtonClickListener());
private class imageButtonListener implements OnClickListener
{
@Override
public void onClick(View button) {
new DisplayImageFromUrl((ImageButton) findViewById(R.id.imageButtonEnd), this).execute(//Enter your link here);
}
<强>更新强> 尝试使用此异步任务
//Display image to bitmap using URL
public class DisplayImageFromUrl extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
Context context1;
ProgressDialog pd;
@Override
protected void onPreExecute() {
super.onPreExecute();
pd = new ProgressDialog(context1);
pd.setMessage("Loading Images...");
pd.show();
}
public DisplayImageFromUrl(ImageView bmImage, Context context) {
this.bmImage = bmImage;
this.context1 = context;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
pd.dismiss();
}
}
你在活动中就这样称呼它。
new DisplayImageFromUrl((ImageButton) findViewById(R.id.imageButtonEnd), this).execute(//Enter your link here);