Picasso download didn't start? - android

#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView imgView = (ImageView) findViewById(R.id.img_view);
Context context = this;
Picasso.with(this)
.load("http://i.imgur.com/DvpvklR.png")
.placeholder(R.drawable.appleadn)
.noFade()
.into(imgView);
}
I am new in android and i use picasso for download images but above with that code give me no error placeholder is also shown but image is downloaded or started yet
where i am wrong?
Or is there flag or something setting for picasso or OkHttp is must for use picasso?

Add this line in your manifest:
<uses-permission android:name="android.permission.INTERNET" />

Related

Glide Image is not showing also getting SSLHandshakeException

The Glide Image is not visible in the app. How can I fix this?
Error log
MainActivity.java:
public class MainActivity extends AppCompatActivity {
ImageView imh;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imh=findViewById(R.id.img);
Glide.with(this)
.load("http://www.image.com/img/seatrade_supplier_logo.jpg")
.centerInside()
.override(100,100)
.into(imh);
}
}
Finally this solved my issue.
Thank you all
Network security configuration

Android ImageView From URL: Not Getting Set (Using Picasso)

I'm brand new to Android development, so I'm probably doing something stupid. Any ideas why this code shouldn't work?
It compiles and runs, but doesn't actually successfully set the image (which is previously set to a gray background).
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_activity);
Button getImageButton = (Button) (findViewById(R.id.btnGetImage));
getImageButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ImageView myImageView = (ImageView) (findViewById(R.id.myImageView));
Picasso.with(v.getContext()).load("https://www.example.com/someimage").into(myImageView);
}
});
}
alter you code this way
Picasso.with(YOUR_ACTIVITY_NAME.this).load("https://www.example.com/someimage").into(myImageView);
Here v.getContext() is not related to the main context, so it won't help you, we need to pass context of current activity
Please try this and let me know.
#Override
protected void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_activity);
Button getImageButton = (Button) (findViewById(R.id.btnGetImage));
ImageView myImageView = (ImageView) (findViewById(R.id.myImageView));
getImageButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Picasso.with(YourActivityName.this).load("https://www.example.com/someimage").into(myImageView);
}
});
}
Ding ding here is my answer
I am sure that you add the dependency
compile 'com.squareup.picasso:picasso:2.5.2'
and used the right url
Picasso.with(v.getContext()).load("http://i.imgur.com/DvpvklR.png").into(imageView);
I am telling you where you went wrong !!
Magic : Have you added the internet permission ? It needs to be in your manifest
<uses-permission android:name="android.permission.INTERNET" />
Rather than that your code is just fine
But i recommend you to use getApplicationContext()
copying from my comment
Picasso is a library and not an application. While creating
Picasso instance if you'll not pass context, then how do you think
it will get the application context from ? For it to work it requires
context , and it definitely needs to be provided by the application
using this library.It also prevents leaking an Activity (if that's
what you pass ,some of below answers have used ) by switching to the
application context. use getApplicationContext()
And for the people who randomly put an answer here read this as well
View.getContext(): Returns the context the view is currently running in. Usually the currently active Activity.
Activity.getApplicationContext(): Returns the context for the entire application (the process all the Activities are running inside
of). Use this instead of the current Activity context if you need a
context tied to the lifecycle of the entire application, not just the
current Activity.
ContextWrapper.getBaseContext(): If you need access to a Context from within another context, you use a ContextWrapper. The
Context referred to from inside that ContextWrapper is accessed via
getBaseContext().
so any way he is accessing the currant activity context.
Cheers!
step 1 In Menifest check Internet Connection
<uses-permission android:name="android.permission.INTERNET" />
step 2 compile "com.squareup.picasso:picasso:2.4.0"
step 3 Image url is not showing any image in browser paste your url in browser and if you get image then you can set that image to imagview
step 4 check url is working or not there is not .png or .jpg extension for imagfile
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_activity);
Button getImageButton = (Button) (findViewById(R.id.btnGetImage));
getImageButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Initializing the ImageView
imageView = (ImageView) findViewById(R.id.imageView);
//Loading Image from URL
Picasso.with(this)
.load("https://www.example.com/someimage")
.placeholder(R.drawable.placeholder) // optional
.error(R.drawable.error) // optional
.resize(400,400) // optional
.into(imageView);
}
});
}

Glide - How load image before dialog show?

I'm working with Glide for server loading images. I need to load image before some dialog shows.
What is the best approach?
EDIT: This is an example from my code:
On my dialog class
#Override
protected void onCreate(final Bundle savedInstanceState) {
setContentView(R.layout.dialog_alert);
ButterKnife.bind(this);
int size = mActivity.getResources().getDimensionPixelSize(R.dimen.product_icon);
String productThumbnailUrl = api.getThumbnailUrl(mProduct.getImage(), size, size);
Glide.with(mActivity)
.load(productThumbnailUrl)
.placeholder(R.drawable.icon_default)
.into(mImage);
}
On my activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
[...]
AlertProduct dialog = new AlertProduct(this, product);
dialog.show();
}
Loading into targets should do what you want.
If you simply want to load a Bitmap so that you can interact with it
in some special way other than displaying it directly to the user,
maybe to show in a notification, or upload as a profile photo, Glide
has you covered.
SimpleTarget provides reasonable default implementations for the much
larger Target interface and let's you focus on handling the result of
your load.

Android using ION with PhotoView Library

My application keeps crashing every time I try to use the PhotoViewAttacher on my application of the PhotoView library. I'm using ION to display images and trying to get the PhotoView library to allow me to zoom into them. My code currently is:
public class massiveImageView extends Activity {
ImageView mImageView;
PhotoViewAttacher mAttacher;
Drawable drawable;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.massive_image_view);
// Any implementation of ImageView can be used!
mImageView = (ImageView) findViewById(R.id.imageViewMassivePage);
Ion.with(this).load("https://pbs.twimg.com/profile_images/522909800191901697/FHCGSQg0.png").withBitmap().asBitmap()
.setCallback(new FutureCallback<Bitmap>() {
#Override
public void onCompleted(Exception e, Bitmap result) {
// do something with your bitmap
drawable=new BitmapDrawable(result);
mImageView.setImageDrawable(drawable);
}
});
mAttacher = new PhotoViewAttacher(mImageView);
}
}
And the error I'm getting is at this line:
mAttacher = new PhotoViewAttacher(mImageView);
Saying:
java.lang.NoClassDefFoundError: uk.co.senab.photoview.PhotoViewAttacher
Any help would be hugely appreciated.
I still don't quite understand why it doesn't work, but I was able to find an answer, where instead of adding the dependency of the library, I just found the jar file online and added that instead, now everything is working perfect.
Library Link

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.

Categories

Resources