Facebook如何在Android中的应用图标上添加徽章数字? [英] How does Facebook add badge numbers on app icon in Android?

查看:1242
本文介绍了Facebook如何在Android中的应用图标上添加徽章数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这里有几个问题,询问是否可以添加一个Android应用程序的徽章,他们都结束了一个没有答案...



但是不知何故最新的Android版测试版本似乎做了一些至少看起来像徽章的东西,即使它在技术上不是这样。



在那篇文章中评论者说这与TouchWiz有些相关。
也在这里他们提到它作为S3 TouchWiz Jelly Bean Addon的功能。



我仍然非常欣赏有关如何做到这一点的信息,如果有一些API可以在我自己的应用程序中使用(在适当的环境中运行) - 即与FB相同的设备演示了这种行为)?

解决方案

我已经弄清楚这是如何为Sony设备完成的。 / p>

我已经发表了关于这里。我也发布了一个关于这个这里






Sony设备使用一个名为 BadgeReciever


  1. 声明 com.sonyericsson.home.permission .BROADCAST_BADGE 您的清单文件中的权限:


  2. 广播 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);


  3. 完成。一旦这个 Intent 被广播,启动器应该在您的应用程序图标上显示徽章。


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

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


我已经排除了我如何找到的细节这是为了保持答案简短,但它都可以在博客中。可能是一个有趣的读者。


I know there are several Qs here that ask if its possible to add badges to an android app and they all end up with a NO answer...

But somehow the latest Facebook beta version for Android seems to do something which at least look like a badge even if it is not technically exactly that.

In that post one of the commenters says that it is somehow related to TouchWiz. And also here they mention it as a feature of the "S3 TouchWiz Jelly Bean Addon".

I still would appreciate information on how does this can be done and if there is some API for this that I can use in my own app (when running in an appropriate environment - i.e. the same device where FB demonstrates this behavior) ?

解决方案

I have figured out how this is done for Sony devices.

I've blogged about it here. I've also posted a seperate SO question about this here.


Sony devices use a class named BadgeReciever.

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

  2. Broadcast an Intent to the 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);
    

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

  4. 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);
    

I've excluded details on how I found this to keep the answer short, but it's all available in the blog. Might be an interesting read for someone.

这篇关于Facebook如何在Android中的应用图标上添加徽章数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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