有没有办法像日历应用程序那样动态更改应用程序图标? [英] Is there any way to dynamically change an app icon like Calendar app does?

查看:333
本文介绍了有没有办法像日历应用程序那样动态更改应用程序图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个Android应用程序,并且想要动态地自动更新应用程序图标,类似于日历图标在用户主屏幕上的更新方式.

I wanna create an Android application, and I want to dynamically and automatically update the app icon similarly to how the calendar icon updates on a user's homescreen.

日历每天更改其图标,以显示月份的日期.还有一个闹钟应用程序,可以更改其图标设置当前时间,换句话说,每分钟更改一次.

The calendar changes its icon for each day showing day of month's number. There is also an Alarm clock app which changes its icon setting the current time, in other words, changing every minute.

那不是小部件,而是一个真实的应用程序图标.然后,它必须有一种方法可以做到这一点.如何在我的应用程序中做到这一点?

That isn't a widget, but a real app icon. Then it must have a way to do so. How can I do it in my app?

推荐答案

无论您的主屏幕是什么,无论您的日历应用程序是什么,也无论闹钟应用程序是什么,它都有特殊的钩子.通常,应用程序无法更新其图标.

Whatever your home screen is has special hooks for whatever your calendar app is and whatever your alarm clock app is. In general, apps cannot update their icons.

钩子是什么意思?

What do you mean by hooks?

例如,三星可以在三星设备上发布三星日历应用程序.在相同的三星设备上,三星的主屏幕可能具有特殊的规则,用于为三星的日历应用程序渲染图标,该规则涉及显示当月的日期.这是因为三星编写了主屏幕.如果您安装第三方主屏幕,则可能不会执行相同的操作.毕竟,我可以在一个小时左右的时间内编写一个主屏幕,并且我对自己不必为三星的日历应用程序做任何特别的事情充满信心.

For example, Samsung can ship a Samsung calendar app on Samsung devices. Samsung's home screen on those same Samsung devices can have special rules for rendering an icon for Samsung's calendar app, rules that involve showing the day of the month. This is because Samsung wrote the home screen. If you install a third-party home screen, it may not do the same thing. After all, I can write a home screen in an hour or so, and I feel quite confident that I don't have to do anything special for Samsung's calendar app.

没有什么可以阻止三星公开某种API来允许开发人员挂接到三星的主屏幕并通知它这种事情.我不能说三星是打算使用第三方的API,还是有人在破解三星如何为自己的应用程序使用它.

There's nothing stopping Samsung from exposing some sort of API to allow developers to hook into Samsung's home screen and notify it about this sort of thing. Whether Samsung intends for third parties to use that API, or whether it is somebody hacking into how Samsung does it for their own apps, I can't say.

(顺便说一句,我在这里引用三星作为一个示例-我不知道他们实际上具有这种功能,如果有的话,他们在哪些设备上也具有这种功能)

(BTW, I am citing Samsung here as a possible example -- I don't know that they actually have this sort of feature, and if so on which devices they have it)

我似乎还记得,有人有一个GitHub项目,该项目试图包装各种主屏幕的专有API. IIRC,一些受支持的功能包括替换应用程序图标或添加徽章(例如,未读邮件数).但是:

I seem to recall that somebody has a GitHub project that tries to wrap the proprietary APIs of various home screens. IIRC, some supported capabilities included either replacing the app icon or adding a badge (e.g., unread message count). However:

  • 只有一小部分设备将支持这些专有API

  • Only a small percentage of devices will support those proprietary APIs

通过逆向工程应用发现的未记录且不受支持的API可能会发生变化,并且可能会以意想不到的方式破坏

Undocumented and unsupported APIs, discovered through reverse-engineering apps, are subject to change and may break in unexpected ways

我非常确定Android SDK中没有支持动态应用程序图标的东西.我所知道的,人们尝试过的唯一一件事是使用<activity-alias>来拥有N个不同的活动",它们全部指向相同的实现,但是具有不同的图标.该应用程序使用PackageManagersetComponentEnabledSetting()禁用旧的启动器别名,并启用其他别名,希望主屏幕对此显示并显示新图标.一些.其他人只有在重新启动后才能了解更改.

I am quite certain that there is nothing in the Android SDK that supports dynamic app icons. The only thing that I know of, that people have tried, is using <activity-alias> to have N different "activities", all pointing to the same implementation, but having different icons. Using PackageManager and setComponentEnabledSetting(), the app disables the old launcher alias and enables a different one, in hopes that home screens will pick up on this and show the new icon. A few do. Others only would find out about the change on a reboot.

要解决这个问题,我可以编写一个主屏幕.也许我想为应用提供某种方式来即时更改其图标,即使没有标准.也许我不知道.也许我根本不打算使用图标,因为我的主屏幕针对视障人士进行了优化,因此它使用的是文字转语音和硬件按键输入.这是我的主屏幕实现,我可以做我想做的事.

To flip the problem around, I can write a home screen. Perhaps I want to offer some way for apps to change their icons on the fly, even though there are no standards for it. Perhaps I don't. Perhaps I do not intend to use icons at all, as my home screen is optimized for the visually impaired, and so it is using text-to-speech and hardware key input. It's my home screen implementation, and I can do what I want.

这篇关于有没有办法像日历应用程序那样动态更改应用程序图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆