I got json data in this way:
{"data":[{"img_name":"abc.jpeg","img_path":"6"}]}
Now How can I display this image in image view in my android application.Please help me to solve.
Not sure if this is what you want.
First you need to parse the JSON and get the img_path and img_name. Then you can create the url of the image. The url generation logic depends on your server logic.
Something like this,
JSONObject data = new JSONObject(your_json_data);
String img_path = data.getString("img_path");
String img_name = data.getString("img_name");
String url = "http://xxx.xxx.x.x/" + img_path + "/" + img_name;
Use an imageloader like Picasso to load the image.
Related
I have a WebApi project and a Android client, and I need to upload some images from the WebApi using App42, the problem is, in this tutorial, it must have a StringPath, but I dont have a stringPath, because the image is gonna be send by the Android Client for the Api and then Save those images. Do I have to send the image from Android as Base64 and then create a tempFileObject as Bitmap and then put the stringPath?
String name = "MyPic";
String userName = "Nick";
String filePath = " file path from gallery /sd card";
String fileType = "IMAGE";
String description = "This is my holiday pic";
Upload upload = uploadService.UploadFileForUser(name,userName,filePath,fileType,description);
// File will get uploaded in App42 cloud with above snippet.
IList<Upload.File> fileList = upload.GetFileList(); // This will have only single file uploaded above
for (int i = 0; i < fileList.Count; i++)
{
Console.WriteLine("fileUrl is " + fileList[i].GetUrl());
//This will return uploaded file URL
}
If I understood the query then you don't have file saved in the device local file storage. If Yes, then you can use another API which will ask you the InputSteam of the image as parameter.
I hope this helps.
when I am trying to upload the default image with captured image,it is not displaying.If I login again then that captured image will display.Why the default image is not changing? In case if the image already exists in the server, it works fine for me.
this is my code.I am using com.android.volley.toolbox.NetworkImageView
String url = "http://xxx.xxx.x.xx/mobile_app/" + img_path + "/" + img_name;
imageLoader = MyVolleyRequest.getInstance(StudentDetails.this).getImageLoader();
imageLoader.get(url, imageLoader.getImageListener(resultIv,R.drawable.new_back, R.drawable.new_back));
resultIv.setImageUrl(url, imageLoader);
Please help me to find the solution.
I have made an android app,In that in an activity I have one imageView,I want to display an image to it using imageLoader,I have been used so many time imageloader,But i got this type of error Image can't be decoded ,My code is as below,Please help me for it,
code
iv_profile = (ImageView) findViewById(R.id.iv_profile);
imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(HomeActivity.this));
options = new DisplayImageOptions.Builder().cacheOnDisc(true).showStubImage(R.drawable.noimage).showImageOnFail(R.drawable.noimage).build();
String img = "http://tp.epagestore.in/" + Pref.getValue(HomeActivity.this, Const.PREF_PHOTO, "");
imageLoader.displayImage(img, iv_profile, options);
I am using this lib:
https://github.com/nostra13/Android-Universal-Image-Loader
I want to load an image thumbnail into an ImageView using the lib.
What content uri can I pass into:
imageLoader.displayImage(imageUri, imageView); //?
The docs give an example of using a content url:
String imageUri = "content://media/external/audio/albumart/13"; // from content provider
I pretty much want to switch from doing this:
return MediaStore.Images.Thumbnails.getThumbnail(context.getContentResolver(), id, MediaStore.Images.Thumbnails.MICRO_KIND, null);
to using the lib.
As you can see I have the id but I need to construct a url for MICRO_KIND image thumbnails...
I think you can use next URI format: content://media/external/images/thumbnails/13
String uri = "content://media/external/images/thumbnails/" + id;
I have a WebView that just displays an image from the external SD-card. This works well, however if the image is overwritten with new data, the WebView does not update the image.
This is even more curious because the WebView is created totally new in the onCreate method of the activity. Here is my code:
#Override
public void onCreate(Bundle savedInstanceState)
{
Log.d(TAG, "Creating Viewer");
super.onCreate(savedInstanceState);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
String imagePath = extras.getString("imgFile");
shareImage(Uri.fromFile(new File(imagePath)));
setContentView(R.layout.viewer_test);
WebView viewer = (WebView) findViewById(R.id.imageViewer);
viewer.getSettings().setAllowFileAccess(true);
viewer.getSettings().setBuiltInZoomControls(false);
viewer.getSettings().setLoadWithOverviewMode(true);
viewer.getSettings().setUseWideViewPort(true);
viewer.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
String filename = "file://"+ imagePath;
String html = "<html><head></head><body bgcolor=\"#000000\"><center><img src=\""+ filename + "\"></center></body></html>";
viewer.loadDataWithBaseURL(null, html, "text/html","utf-8", null);
viewer.reload();
}
The image at the path that is saved in imagePath is overwritten by another activity before the path is sent to this activty. The WebView however still shows the old image data.
As you can see I already tried to set the cache mode and I tried to manually reload the WebView, with no luck unfortunately.
I also checked with a file manager and the image on the SD-card is overwritten with new data. I tried to overwrite the file multiple times, but that doesn't work either. Somehow the image data gets cached somewhere or something. How can I avoid this and load the new data every time?
(Obviously creating a new file with a different filename works fine, but I want to replace the old file.)
I'm not too familiar with Webview. but in ordinary websites you can use the querystring to emulate a unique adress, while still loading same image. this is often used on webpages on css files.
example: http://www.webpage.com/image.jpg?cachekey=23456456754
by randomizing the cachekey every time the image loaded, it is treated as a unique image and does not load from cache.
Put a randomized int or string in the end of your filename string
Random r = new Random();
int randInt = r.nextInt(8000000-1000000) + 1000000;
String query = "?cachekey=" + randInt ;
String html = "<html><head></head><body bgcolor=\"#000000\"><center><img src=\""+ filename + query "\"></center></body></html>";
I have not tested this yet. but it's an idea how to solve it.