如何添加一个通知徽章/数到对索尼Xperia设备的应用程序图标? [英] How to add a notification badge/count to application icon on Sony Xperia devices?

查看:308
本文介绍了如何添加一个通知徽章/数到对索尼Xperia设备的应用程序图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用索尼的Xperia家,某些应用程序都显示计数泡沫或徽章上的应用程序图标的能力。 Facebook和Facebook的Messenger的双方做到这一点,以及内置的电子邮件应用程序。

With Sony's Xperia Home, certain apps have the ability to display a count bubble or badge on the app icon. Facebook and Facebook Messenger both do this, as well as the built in Email app.

这一直是<一href="http://stackoverflow.com/questions/20136483/how-do-you-interface-with-badgeprovider-on-samsung-phones-to-add-a-count-to-the">solved对于三星的发射,但我还没有碰到过任何文件,就如何做到这一点对索尼的发射。

This has been solved for Samsung's launcher, but I have not come across any documentation on how to do it for Sony's launcher.

如何能不能做到?

推荐答案

在看到三星的发射器,它采用了BadgeProvider处理徽章丹尼尔·奥查娅的解决方案后,我开始做同样的索尼的Xperia家。这个答案是直接<一href="http://marcusforsberg.net/blog/android-how-to-add-a-notification-badge-to-app-icon-on-sony-xperia-devices/">from我的博客。

After having seen Daniel Ochoa's solution for Samsung's launcher, which uses a BadgeProvider to handle the badges, I set out to do the same for Sony's Xperia Home. This answer is taken directly from my blog.

我偶然发现索尼AppXplore ,并用它来看看许可的Facebook应用程序的。 Facebook应用程序请求以下权限,这是关键,以索尼设备上显示徽章:

I stumbled upon Sony's AppXplore and used it to check out the permission's of the Facebook app. The Facebook app requests the following permission, which is the key to displaying badges on Sony devices:

com.sonyericsson.home.permission.BROADCAST_BADGE

com.sonyericsson.home.permission.BROADCAST_BADGE

接下来,我必须通过所有可用的内容提供商一起来看看但我没有发现任何相关的应用程序图标徽章那里。 我跑了这个答案 href="http://stackoverflow.com/a/4698597/1546986">命令来获取系统转储文件的

Next, I had a look through all available content providers but I found nothing related to app icon badges there. I ran the command in this answer to get a system dump file and searched for "badge" using Notepad++. I found this:

com.sonyericsson.home.action.UPDATE_BADGE:   41be9a90 com.sonyericsson.home / .BadgeService $ BadgeReceiver过滤41be9858

com.sonyericsson.home.action.UPDATE_BADGE: 41be9a90 com.sonyericsson.home/.BadgeService$BadgeReceiver filter 41be9858

所以,它使用在索尼BroadcastReciever相对于三星的内容提供商处理。所以,我创建了自己的虚拟BroadcastReciever,监听行动com.sonyericsson.home.action.UPDATE_BADGE,发现通过索尼公司的BadgeService的花絮。 对于这一点,我还需要一个许可,但很容易发现,在转储文件:

So, it's handled using a BroadcastReciever on Sony as opposed to Samsung's Content Provider. So, I created a dummy BroadcastReciever of my own, listening for the action com.sonyericsson.home.action.UPDATE_BADGE, and found the extras passed to Sony's BadgeService. For this, I also needed a permission, but that was easy to find in the dump file:

com.sonyericsson.home.permission.RECEIVE_BADGE

com.sonyericsson.home.permission.RECEIVE_BADGE

被Facebook,电子邮件应用程序等发出的临时演员,分别是:

The extras sent by Facebook, the Email app, etc, are:

  • com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME - 的 您的应用程序的主要活动,android.intent.action.MAIN的名字。这是 所以发射知道哪个图标以显示对徽章。
  • com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE - 一个 boolean值,指示我们要显示的徽章或不(这是我们做的!)
  • com.sonyericsson.home.intent.extra.badge.MESSAGE - 一个字符串 (不是整数 - 是我花了一段时间来实现......)与数 显示。
  • com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME - 您的应用程序包的名称
  • com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME - The name of your app's main activity, android.intent.action.MAIN. This is so the launcher knows which icon to show the badge on.
  • com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE - a boolean indicating if we want to show the badge or not (which we do!)
  • com.sonyericsson.home.intent.extra.badge.MESSAGE - a string (not an integer - that took me a while to realize...) with the number to show.
  • com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME - The name of your application package.

所以,事实证明这是非常简单的显示徽章上的启动应用程序的图标。国际海事组织它更直截了当比三星的发射。 这里有一个一步一步的引导(和它的不长!)

So, it turns out it's very simple to show a badge on your application icon in the launcher. IMO it's much more straight-forward than for Samsung's launcher. Here's a step-by-step-guide (and it's not long!)

  1. 声明 com.sonyericsson.home.permission.BROADCAST_BADGE 允许在你的manifest文件:

  1. Declare the com.sonyericsson.home.permission.BROADCAST_BADGE permission in your manifest file:

播出的意图 BadgeReceiver

Intent intent = new Intent();

intent.setAction("com.sonyericsson.home.action.UPDATE_BADGE");
intent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", "com.yourdomain.yourapp.MainActivity");
intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", true);
intent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", "99");
intent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", "com.yourdomain.yourapp");

sendBroadcast(intent);

  • 完成。一旦这个意图广播发射应显示在您的应用程序图标徽章。

  • Done. Once this Intent is broadcast the launcher should show a badge on your application icon.

    要删除的徽章一遍,只需发送一个新的广播,这次 SHOW_MESSAGE 设置为false:

    To remove the badge again, simply send a new broadcast, this time with SHOW_MESSAGE set to false:

    intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", false);
    

  • 由于信息字符串,你其实可以添加单词徽章:


    Good to know

    The message is a string!

    Since MESSAGE is a String, you can actually add words to the badge:

    intent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", "Testing");
    

    但我不会做,因为那只是看起来怪怪的。

    But I wouldn't do that 'cause it just looks weird.

    BROADCAST_BADGE 权限不会只给你访问自己的应用程序的图标,但他们所有人。例如,这里是你如何设置Facebook的徽章:

    The BROADCAST_BADGE permission does not only give you access to your own app's icon, but to ALL of them. For example, here's how you can set Facebook's badge:

    Intent intent = new Intent();
    intent.setAction("com.sonyericsson.home.action.UPDATE_BADGE");
    intent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", "com.facebook.katana.LoginActivity");
    intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", true);
    intent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", "99");
    intent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", "com.facebook.katana");
    
    sendBroadcast(intent);
    


    我希望这一直是帮助别人! :)


    I hope this has been of help to someone! :)

    这篇关于如何添加一个通知徽章/数到对索尼Xperia设备的应用程序图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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