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

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

问题描述

我知道有一堆这样的问题,但我的是不同的。不同之处在于,我想创建一个Android应用程序,我想动态地自动更新应用程序图标,与用户主屏幕上日历图标更新的方式类似。

I know there are a bunch of questions like this one, but mine is different. The difference is that 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,我在这里引用三星作为一个可能的例子 - 我不知道他们实际上有这样的功能,如果是这样的功能)

(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个不同的活动,都指向相同的实现,但是有不同的图标。使用 PackageManager setComponentEnabledSetting(),该应用程序会禁用旧的启动器别名,并启用不同的,希望在家屏幕将会接收并显示新的图标。几个。其他人只会发现重新启动的更改。

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.

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

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