I am making an android app in which i need to display the remote images in my app
my using following code.
but the images are not being displayed:
for(int i=0;i<stringOnTextView.length;i++){
imageUrl = "http://ondamove.it/English/images/users/";
imageUrl = imageUrl+stringOnTextView[i];
System.out.println(imageUrl);
URL myFileUrl = new URL(imageUrl);
HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bmImg = BitmapFactory.decodeStream(is);
image.setImageBitmap(bmImg);
System.out.println(bmImg.toString());
}
Can anyone tell me where is the problem. thanks
as a completion of my comment , see this three tutorials and you will find out what you should do :) :
tuto1
tuto2
tuto3
Related
This is a part of my function:
public void getUrls(String category) {
try {
String url = "my_url"
URL imagesJSON = new URL(url);
HttpURLConnection conn = (HttpURLConnection) imagesJSON.openConnection();
conn.setConnectTimeout(30000);
conn.setReadTimeout(30000);
conn.setInstanceFollowRedirects(true);
InputStream is = conn.getInputStream();
conn.disconnect();
I expect to get JSON data from a server and return it to another function. I gonna get some URLs from this JSON and return them. I am wondering which type should this function be and if I should use some function to format recieved object to operate on in properly. I will be grateful for some clues and tips.
Try this tutorial. Android Parsing JSON Data
I'm trying to download GIF from given Url but there is a problem. I'm stuck here and don't know the correct way to download this file. How to repair this? I have sample url: http://i1.kwejk.pl/k/obrazki/2015/02/6f0239004a643dbd9510ebda5a6f22b3.gif
My code:
try{
System.out.println(this.adressToGif);
URL url = new URL(urltoGif);
URLConnection conn = url.openConnection();
//conn.connect();
InputStream is = conn.getInputStream(); //IT crashes here and jumps to catch()
BufferedInputStream bis = new BufferedInputStream(is);
bis.mark(conn.getContentLength());
bis.close();
gifPlayer = new NewGifPlayer(this, bis);
//Movie movie = Movie.decodeStream(bis);
}catch(Exception x)
{
System.out.println("There is a problem");
}
You cannot run networking operations on the main thread. Use AsyncTask for that.
I have an online video url, I can use vitamio video player play it online, but once I use android HttpUrlConnection download, I failed and received http 405 error.Can anyone give me some help?
HttpURLConnection conn = null;
int totalSize = 0;
conn = (HttpURLConnection) new URL(url).openConnection();
conn.setConnectTimeout(10 * 1000);
conn.setRequestMethod("GET");
conn.connect();
totalSize = conn.getContentLength();
[1]:http://219.238.10.102/videos/v0/20140303/43/4c/69/cd1e834831bfafcdef321e0037050f45.mp4?key=9070001543d27aea&path=/data1/www&m=DC96181615C9D859EB81DA194598DF31A8A3F8DBD9CC94AB612C1489A6574E08E898F5CE76C1BA00DEEE348748C27D82DCCEF4183D058C45DD96616D9D87753F263ADF611C41D0531BA1BDCFD7DE9B16&uuid=4cc6f4b2f1d7b13fa4fd9b4233e0094fc016327ac6ddc126dc54d6f359bcca4b
the url is [the url of a video][1]
I put the url on http://web-sniffer.net/, it displayed right length which is 71917427.
This problem was finally solved by add userAgent:
conn.setRequestProperty("User-agent", "");
My app should download many pictures from one website,the number is more than 200.So if i put this below code in a for(int i = 0; i++ ; i < 200),it looks not nice,the connection should connect and disconnect every time.
So anybody have some good suggestions?
URL imageUrl = new URL(url);
conn = (HttpURLConnection)(imageUrl.openConnection());
conn.connect();
InputStream is = conn.getInputStream();
BitmapFactory.Options ops = new BitmapFactory.Options();
ops.inSampleSize = inSample;
bitmap = BitmapFactory.decodeStream(is, null, ops);
is.close();
conn.disconnect();
URLConnection pooling happens behind the scenes. You don't have to worry about it yourself.
Since each image have a separate url, connection have to open and closed. There are no alternatives for this code.
I need help with sending http get request. Like this:
URL connectURL;
connectURL = new URL(address);
HttpURLConnection conn = (HttpURLConnection)connectURL.openConnection();
// do some setup
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("GET");
// connect and flush the request out
conn.connect();
conn.getOutputStream().flush();
// now fetch the results
String response = getResponse(conn);
et.setText(response);
I searched the web but any method I try, the code fails at 'conn.connect();'. Any clues?
Very hard to tell without the actual error message. Random thought: did you add the internet permission to you manifest?
<uses-permission android:name="android.permission.INTERNET"/>
If you want some demo code then try following:
URL url = new URL("url.com");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
try {
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
readStream(in);
} finally {
urlConnection.disconnect();
}
and this:
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
try {
urlConnection.setDoOutput(true);
urlConnection.setChunkedStreamingMode(0);
OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
writeStream(out);
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
readStream(in);
} finally {
urlConnection.disconnect();
}
Hope this helps.