I have an app where i am adding shortcut. I want to add shortcut icon image from URL path(images are stored on server and can be change) instead of using Drawable but i don't know how to do that. I tried to find a lot on this community. Any help?
Asked
Active
Viewed 1,213 times
1
-
what is shortcut there ? any view in the app or widget or something else. Elaborate – Dushyant Suthar Apr 03 '17 at 08:59
-
did you mean app icon? – an_droid_dev Apr 03 '17 at 09:00
-
yes...app icon.. – Abhishek shrivastava Apr 03 '17 at 09:05
-
@Abhishekshrivastava this question should solve your problem http://stackoverflow.com/questions/1103027/how-to-change-an-application-icon-programmatically-in-android – an_droid_dev Apr 03 '17 at 09:14
-
@an_droid_dev this question does not provide the answer. I want to add shortcuts and the shortcut icons should be from server url.... example - addShortcut(String appname,String appiconurl){ } – Abhishek shrivastava Apr 03 '17 at 09:19
-
@Abhishekshrivastava The question is seriously unclear. According to what you wrote lower down in a comment to my answer you want to pass it as an extra. You need to explain better exactly what you are attempting. – theblitz Apr 03 '17 at 15:42
-
@theblitz i have an app where there are some tiles in grid view and that icons are coming from server. now each item has add to shortcut option where i can put that specific item on homescreen to open their contents directly. and i have done that. But now i want to give them their respective icons image. But Intent.EXTRA_SHORTCUT_ICON only accepts resource id which are in drawable or accepts bitmap. So i want to load url directly from server instead of taking from drawable – Abhishek shrivastava Apr 04 '17 at 12:57
-
In that case use what Awais wrote below but put it into a variable instead of into an imageView – theblitz Apr 04 '17 at 13:08
-
@Abhishekshrivastava were you able to get the answer to this? – GOVIND DIXIT Dec 04 '20 at 14:41
3 Answers
0
If the term used "shortcut icon" is a view or its descendants such as ImageView
, then you can set the image, your application receive from the server by doing this :
add dependency to your app.gradle
file :
compile 'com.github.bumptech.glide:glide:3.7.0'
and in the activity you can use this method to set the image to the imageview
your app receive from the server :
ImageView imageView = (ImageView) findViewById(R.id.image_view);
Glide.with(imageview.getContext()).load("https://url").error(R.drawable.not_found).centerCrop().into(imageview);

Dushyant Suthar
- 673
- 2
- 9
- 27
-
I personally prefer Picasso. If you want details about the differences then see this thread: http://stackoverflow.com/questions/29363321/picasso-v-s-imageloader-v-s-fresco-vs-glide. Well worth the read – theblitz Apr 03 '17 at 09:14
-
No...actually i want to add shortcut icons from this line of code intent..putExtra(Intent.EXTRA_SHORTCUT_ICON, R.drawable.your_image); in place of drawable i want to load the image from my server – Abhishek shrivastava Apr 03 '17 at 09:14
-
@theblitz thank you very much for your contribution but I used to use `picasso` then I moved to glide for this reason https://medium.com/@multidots/glide-vs-picasso-930eed42b81d – Dushyant Suthar Apr 03 '17 at 09:20
-
i think this cant be done with any image loading library. @theblitz you understand the question correctly? – Abhishek shrivastava Apr 03 '17 at 09:23
-
@Abhishekshrivastava That's exactly what Picasso and Glide do. They fetch images from a URL and put them where you want in your app - including as icons. – theblitz Apr 03 '17 at 15:40
0
What you could do is first download that icon and store locally and then take that file path and use
ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(this, UUID.randomUUID().toString())
.setIntent(intent) // !!! intent's action must be set on oreo
.setShortLabel(lable)
.setIcon(IconCompat.createWithAdaptiveBitmapContentUri(filePath)).build();
ShortcutManagerCompat.requestPinShortcut(this, shortcutInfo, null);

prem
- 41
- 5
-2
add this in your build.gradle
compile 'com.squareup.picasso:picasso:2.5.2'
now you can load the image using following code
Picaso.with(this).load(urlHere).into(imageView);

AwaisMajeed
- 2,254
- 2
- 10
- 25
-
1Please see my question. I know how to load images from picasso,glide,volley etc. I want to add shortcut icon from url through intent services – Abhishek shrivastava Apr 03 '17 at 09:37