Skip to content Skip to sidebar Skip to footer

Xamarin Set Custom Icon For Shortcut

I use this code but this does not work. There are no exceptions but custom icon does not work. I don't want to use 'Resource.Drawable.example_icon_bla_bla' I want to set icon from

Solution 1:

I have fixed with this lines;

    private void AddShortcut(string appName, string url, byte[] icon_byte)
            {
                try
                {
                    Bitmap bitmap = BitmapFactory.DecodeByteArray(icon_byte,0,icon_byte.Length); 
                     // 72x72 best size for launcher icon.
    
                    var uri = Android.Net.Uri.Parse(url);
                    var intent_ = new Intent(Intent.ActionView, uri);
    
                    Intent installer = new Intent();
                    installer.PutExtra("android.intent.extra.shortcut.INTENT", intent_);
                    installer.PutExtra("android.intent.extra.shortcut.NAME", appName);
                    installer.PutExtra("android.intent.extra.shortcut.ICON", bitmap);
                    installer.SetAction("com.android.launcher.action.INSTALL_SHORTCUT");
                    SendBroadcast(installer);
                }
                catch (Exception) { 
                    //Toast.MakeText(this,"Shortcut: " +ex.Message, ToastLength.Long).Show(); 
                }
    
            }

Post a Comment for "Xamarin Set Custom Icon For Shortcut"