Ritu
Ritu

Reputation: 676

Load Drawable as String in Glide

I need to replace image path from server into vector drawable so i can load vector icon in Glide. I have tried several method like these but it shows error

 uri = Uri.parse("android.resource://"+context.getPackageResourcePath()+"/drawable/ic_vector_icon");

 uri = Uri.parse("android.resource://com.squishy/drawable/ic_vector_icon");

 String ImagePath = "drawable://"+R.drawable.ic_vector_icon;
                    
 String ImagePath = uri.toString();

Error Shows when this path load in Glide

java.io.FileNotFoundException(No package found for authority: android.resource://com.squishy/2131232629)

Logic:- If image from server is null then load default image from drawable folder. This string is dynamic and not possible to make changes in all Glide calls with if/else

Is there any way to resolve this issue?

Upvotes: 0

Views: 750

Answers (1)

Greeshma
Greeshma

Reputation: 412

for your usecase cant you use the placeholder in Glide

Glide.with(context)
        .load(imageUrl)
.placeholder(ContextCompat.getDrawable(context,R.drawable.ic_vector_icon
    ))
        .transition(DrawableTransitionOptions.withCrossFade())
        .into(binding.dealImage)

Upvotes: 0

Related Questions