Here, we are going to see that how to load image from Internet. This will help in such applications where the images are changes periodically. Other applications where data comes from internet, this tutorial will help them. Database stores the path of image. So, by using path of image, we can download it into our application.
To make connection from application to internet following permission will be required. Just past this code in manifest.xml file such that it will become the child node of manifest node.
<uses-permission android:name="android.permission.INTERNET"/>
Following is the whole source code. You can download the pdf file from here, imageload.java.
public class xmlimage extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ImageView img=new ImageView(this); Drawable drawable = LoadImageFromWebOperations("http://" + "blog.sptechnolab.com/wp-content/uploads/2011/02/c2.jpg"); img.setImageDrawable(drawable); setContentView(img); } private Drawable LoadImageFromWebOperations(String url){ try{ InputStream is = (InputStream) new URL(url).getContent(); Drawable d = Drawable.createFromStream(is, "src name"); return d; }catch (Exception e) { System.out.println("Exc="+e); return null; } } }
Output of the above application will be as shown below, here image is load from the url given in the example. So, you can dynamically change the image from server side.
Image may be NSFW.
Clik here to view.
Following are the links of other Post on Android.
Android : ContextMenu & SubMenu
Android : Connecting to MySQL using PHP
Android : Sliding Drawer
Android Countdown Timer
Getting started with Android Map View: Displaying a location by Marker
Simple Progress Bar in Android using Thread
Android listview with image and text
Manage & Developed by Sptechnolab.com