Setting an Android Notification Icon to a remote URL

情到浓时终转凉″ 提交于 2019-12-18 07:38:21

问题


I want to use a remote URL (like a favicon) for a notification icon, however the constructor for a notification accepts only a resource ID (which is an integer) instead of something more useful like a FileInputStream.

How can I either

  • define a new resource for a stream source

  • download an icon, add to my resources, and then dynamically get an ID?


回答1:


You can't do this in Android currently, because resources can only be loaded from the /res/ directory of your APK. See Resources and Internationalization. The /res/ directory is built when you create your APK and can't be changed after.

Do you expect your Icon to change often enough that you need to query a URL to ensure it is up to date every time you send a notification?

Most applications that need to change their icon would simply put an update out on the Android market.




回答2:


Since API 11 Android has had the ability to use a Bitmap for a largeIcon in notifications. This has been expanded even further in Jelly Bean to allow entire notifications to be an image, BigPictureStyle.



来源:https://stackoverflow.com/questions/2059933/setting-an-android-notification-icon-to-a-remote-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!