how to retrieve image which stored in cloud - android

image stored in cloud "https://www1.copy.com/home/ganesh.jpg" on this link ..and i am not able to get image in application
public class AndroidLoadImageFromURLActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Loader image - will be shown before loading image
int loader = R.drawable.loader;
// Imageview to show
ImageView image = (ImageView) findViewById(R.id.image);
// Image url
String image_url = "https://www.copy.com/browse/copy/0017.JPG";
// ImageLoader class instance
ImageLoader imgLoader = new ImageLoader(getApplicationContext());
// whenever you want to load an image from url
// call DisplayImage function
// url - image url to load
// loader - loader image, will be displayed before getting image
// image - ImageView
imgLoader.DisplayImage(image_url, loader, image);
}
}

Problem :
The link https://www1.copy.com/home/ganesh.jpg doenst return an image.
maybe you you need to login to the site and then you can get the image.
Solution :
Try ot get the srouce code of the ImageLoader jar and try to modify the URLConnection and pass the credentials to log in to the site.

Related

Assign image resource in an image view with string

(1) I am using recyleview to fetch image, text & audio file from API. For text I used volley & for image use picasso, what I will use for audio file.
(2) after fetch the image & text when apply onclicklistener pass the info to another activity. Can pass only text not images.
What I need to do to solve this problem?
this is adapter part
viewHolder.textViewStory.setText(banglaItem.getStoryName());
viewHolder.textViewWritter.setText(banglaItem.getWritterName());
Picasso.get().load(banglaItem.getStoryImage()).fit().into(viewHolder.imageView);
viewHolder.linear.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context,AudioActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("storyName",banglaItem.getStoryName());
intent.putExtra("storyImage",banglaItem.getStoryImage());
context.startActivity(intent);
}
});
this is the new activity part
public class AudioActivity extends AppCompatActivity {
TextView name;
ImageView image;
String nameStory;
String imageStory;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_audio);
name = findViewById(R.id.audioName);
image = findViewById(R.id.audioImage);
nameStory = getIntent().getStringExtra("storyName");
imageStory = getIntent().getStringExtra("storyImage");
name.setText(nameStory);
int resourceId = getResources().getIdentifier(imageStory,"drawable", getPackageName());
image.setImageResource(resourceId);
}
}
(1.) if you have complete url of your audio file then you can directly stream audio file using media player classes provided by android.
(2.) you are passing storyImage in next activity ,which is a url that you get from api. so you have to find same on next activity i.e
TextView name;
ImageView image;
String nameStory;
String imageStory;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_audio);
name = findViewById(R.id.audioName);
image = findViewById(R.id.audioImage);
nameStory = getIntent().getStringExtra("storyName");
imageStory = getIntent().getStringExtra("storyImage");
name.setText(nameStory);
Picasso.get().load(imageStory).fit().into(image);
//here image story contain url that you sent through first activity. As picasso uses cache, it will load (already loaded image in first activity) very smoothly from it cache.
}

How to reload NetworkImageView

I have an app which is displaying fragment with one NetworkImageView widget from android Volley.
The image at URL which is loaded in NetworkImageView is changing every 5 secounds so I want to uptade this image by pressing reload button that I have created in action bar.
I have found 2 problems:
If I call this code for loading Image again(it was already called when the fragment was created at onActivityCreated() method):
mNetworkImageView = (NetworkImageView) getView().findViewById(R.id.networkImageView);
mImageLoader = VolleySingleton.getInstance(getActivity()).getImageLoader();
mNetworkImageView.setImageUrl(IMAGE_URL, mImageLoader);
so nothing will happens(it is not the actual IMG of that link), I think its because it is now loading IMG from cache and not from internet.
If I call fragment reload() method:
public void reload(){
MainActivity activity = (MainActivity) getActivity();
IMAGE_URL = activity.getMyData();
mNetworkImageView = (NetworkImageView) getView().findViewById(R.id.networkImageView);
mImageLoader = VolleySingleton.getInstance(getActivity()).getImageLoader();
mNetworkImageView.setImageUrl(IMAGE_URL, mImageLoader);
from MainActivity:
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
if (id == R.id.action_reload) {
ViewFragment fragment = new ViewFragment();
fragment.reload();
}
return super.onOptionsItemSelected(item);
}
app get NullPointerException error after clicking action bar reload button.
the reload(); method is the place where I would like to reload NetworkImageView.
Can someone explain me pls how to correct this issues?
First get the cache from request queue.
Then remove your URL from the cache by calling remove function from the cache ( the key is your url).
then use your first approach:
mNetworkImageView = (NetworkImageView) getView().findViewById(R.id.networkImageView);
mImageLoader = VolleySingleton.getInstance(getActivity()).getImageLoader();
mNetworkImageView.setImageUrl(IMAGE_URL, mImageLoader);
This question and answers look old but those answers doesn't work on my project.
For your help, I write my solution here.
The problem is Volley's NetworkImageView caching the image as a map and there is no API for init the cache map.
Therefore my solution is make custom cache class which is includes removeCacheAll().
public class ImageCacheTrunk implements ImageLoader.ImageCache {
#Override
public void putBitmap(String url, Bitmap bitmap) {
mCache.put(url, bitmap);
}
#Override
public Bitmap getBitmap(String url) {
return mCache.get(url);
}
public void removeCacheAll() {
mCache.evictAll();
}
}
and call removeCacheAll method before you need to reload.

Android - ImageLoader won't re-retrieve the image from URL

This is the Activity page named PicURL. I want the app to retrieve the image from the URL whenever this Activity Page is called.
The problem is that this activity page will retrieve the image only once (the first time the activity is called.)
For instance, I open this activity I got picture "A" from the URL. Then I overwrite the picture "A" with picture"B". I reopen this activity but I still got picture "A" which it should be picture"B".
public class PicURL extends Activity {
ImageView imageView;
private ImageLoader imageLoader;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pic_url);
imageLoader = ImageLoader.getInstance();
imageView = (ImageView) findViewById(R.id.imageView);
DisplayImageOptions.Builder optionBuilder = new DisplayImageOptions.Builder();
optionBuilder.showImageForEmptyUri(R.drawable.ic_launcher);
optionBuilder.showImageOnFail(R.drawable.ic_launcher);
optionBuilder.cacheInMemory(true);
optionBuilder.cacheOnDisk(true);
DisplayImageOptions options = optionBuilder.build();
ImageLoaderConfiguration.Builder loaderBuilder =
new ImageLoaderConfiguration.Builder(getApplicationContext());
loaderBuilder.defaultDisplayImageOptions(options);
loaderBuilder.diskCacheExtraOptions(400, 400, null);
ImageLoaderConfiguration config = loaderBuilder.build();
if (!imageLoader.isInited()) {
ImageLoader.getInstance().init(config);
} // Checked if ImageLoader has been initialed or not.
String imageUri = "http://abcdef.com/pic1.png"; //Where the app retrieve the image from the link
imageLoader.displayImage(imageUri, imageView);
}
Apologize for my poor English.
Thanks for help!
Seem like you have ImageLoader's cache enabled:
optionBuilder.cacheInMemory(true);
optionBuilder.cacheOnDisk(true);
You need to set these options to false.
Disable caching will make your app re-load every images from the internet every time, which might be undesirable for you or your users.
You may enable caching, but generate a random query string to the URL that you really want to reload, e.g.,
String randomString = String.format("?random=%d", System.currentTimeMillis());
String imageUri = "http://abcdef.com/pic1.png"+randomString;
imageLoader.displayImage(imageUri, imageView);

Trying to load pictures from url using novoda ImageLoader

hi I am trying to load an image from an url using novoda Direct ImageLoader method
right now I have this class
public class MainActivity extends Activity {
public class DirectLoading extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView iv=(ImageView) findViewById(R.id.imageView1);
ImageView ivv=(ImageView) findViewById(R.id.imageView2);
Bitmap b=new DirectLoader()
.download("https://upload.wikimedia.org/wikipedia/commons/a/ad/SmallStellatedDodecahedron.jpg");
Bitmap pic=new DirectLoader()
.download("http://www.coetail.com/mamitakagi1129/wp-content/themes/twentyten/images/headers/cherryblossoms.jpg");
ivv.setImageBitmap(pic);
iv.setImageBitmap(b);
}
private void guiBuilder() {
}
}
}
I should get 2 images into the 2 imageViews, but I am getting a blank screen. There is a "Hello world" string in the layout that is not displayed so I guess I do get the images but they are not displayed graphically.
As it says in readme file https://github.com/novoda/ImageLoader/blob/develop/README.md you should handle threading when using DirectLoader.download(), for example, using AsyncTask.

Display screenshot image from one activity to another activity

I am developing playing video application and taking screenshot of running video and display a screenshot in next activity, i am playing video and taking screenshot and i am not able to display screenshot in next activity please check my code and give me changes.
BitmapDrawable bitmapDrawable = new BitmapDrawable(bm);
image = (ImageView) findViewById(R.id.ImageView01);
// image.setBackgroundDrawable(bitmapDrawable);
String bitmap = image.toString();
System.out.println("Image getting++++++ : " + bitmap);
Intent intent = new Intent(VideoDemo.this, ScreenshotView.class);
intent.putExtra("BitmapImage", bitmap);
startActivity(intent);
public class ScreenshotView extends Activity
{ private String filename;
private ImageButton back;
private ImageView screenshot;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.screenshot);
screenshot =(ImageView)findViewById(R.id.screen);
back = (ImageButton)findViewById(R.id.backbutton);
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
finish();
}
});
System.gc();
Intent i = getIntent();
Bitmap bitmap = (Bitmap) i.getParcelableExtra("BitmapImage");
screenshot.setImageBitmap(bitmap);
}
}
Here your "bitmap" object is a string.
And you are passing a string object to your next activity.
That is why, you are not able to set image in you ImageView screenshot.
Can you try the below code and lemme know whether you fixed it.
Sending Object
Here is the code to send the Object from one to other class. One Important thing to send the Object is the class should implement the Serializable class.
The below Red Colored text should be same.
//MainActivity.java
Intent i = new Intent(MainActivity.this,startActivity.class);
ObjectClassName object = new ObjectClassName();
i.putExtra("THIS", Object);
Receiving Object
// startActivity.java
Intent i = getIntent();
ObjectClassName obj = (ObjectClassName) getIntent().getSerializableExtra("THIS");//
TypeCasting needed

Categories

Resources