High-grade shortcuts with icons

I am trying to create a desktop shortcut programmatically on Android. So far I have managed to add a shortcut with the following code:

Intent shortcutIntent = new Intent(); shortcutIntent.setClassName(mContext, mContext.getClass().getName()); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); shortcutIntent.putExtra("someParameter", "HelloWorld 123"); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Shortcut Name 123"); addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, R.drawable.icon); addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); mContext.sendBroadcast(addIntent); 

But the shortcut is set using the default icon in my resources. However, I would like to receive icons from my site and add the icon to the shortcut. First, I need to download this shortcut. Under the assumption that I did this and the icon on the SD card, for example, I was unable to set the shortcut.

The following code:

 try { Uri contentURI = Uri.parse("http://mnt/sdcard/mytest/test.png"); ContentResolver cr = mContext.getContentResolver(); InputStream in; in = cr.openInputStream(contentURI); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize=8; Bitmap thumb = BitmapFactory.decodeStream(in,null,options); Intent shortcutIntent = new Intent(); shortcutIntent.setClassName(mContext, mContext.getClass().getName()); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); shortcutIntent.putExtra("someParameter", "HelloWorld 123"); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Shortcut Name 123"); addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, thumb); addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); mContext.sendBroadcast(addIntent); } catch (FileNotFoundException e) { e.printStackTrace(); } 

The file definitely exists, and I checked that using the adb shell ... This piece of code shows the following error:

 10-13 16:11:31.184: WARN/System.err(23273): java.io.FileNotFoundException: No content provider: /mnt/sdcard/mytest/test.png 

What am I doing wrong?

thanks

+4
source share
2 answers

You are trying to get a bitmap from local resources (using a content provider).

To download Bitmap from the server, you must follow this:

Why is this bitmap not loading on Android?

+1
source

It looks like your application cannot access test.png. Make sure it exists. Perhaps you can start with local storage and not with an SD card.

0
source

All Articles