添加通知徽章的Andr​​oid应用程序图标 [英] adding notification badge on app icon in android

查看:196
本文介绍了添加通知徽章的Andr​​oid应用程序图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可能会认为这是一个重复的问题,但我想答案比类似于此的任何问题更为具体。

you may think that this is a duplicate question but i want answers to be more specific than any questions that are similar to this.

首先它说,有通知的徽章与三星的设备,如Facebook。 <一href="http://stackoverflow.com/questions/17510419/how-does-facebook-add-badge-numbers-on-app-icon-in-android">How不添加Facebook的徽章数量的应用程序图标中的Andr​​oid?。它原来是TouchWiz的发射可能是三星设备的默认启动。当我试图用新星发射测试我的三星设备。它需要安装一些第三方软件或新星TestlaUnread。

first it says that like facebook having notification badge with samsung device. How does Facebook add badge numbers on app icon in Android?. and it turns out to be the touchwiz launcher which may be the default launcher of samsung devices. when i tried to test my samsung device with nova launcher. it needs to install some third party software or Nova TestlaUnread.

继承人的事实。我想了TouchWiz是增加徽章的所有应用程序,但是当我尝试来测试我的应用程序有一些通知,它不显示任何标志。因为我发现,三星的TouchWiz只显示应用到选定的应用程序,如规定在这里: 对于通知 UI的帮助图标

Heres the fact. i thought the touchWiz is adding badge for all application, but when i try to test with my app to have some notification, it doesn't show any badge. as i found out that samsung TouchWiz only showing app to selected app as stated here: UI help for Notification on icon

现在的问题是:有没有什么办法让知道的TouchWiz添加徽章到我的应用程序图标 这对于三星的设备,

The question is: is there any way to let know the touchWiz to add badge to my app-icon? That's for the samsung device,

与previous争论,好像不同厂商的发射器是一个负责的应用程序图标徽章的机器人。索尼Experia还采用Experia还首页/发射器作为其默认启动。在我的索尼设备,他们在那里短信或漏接电话或Facebook徽章。

with that previous arguments, it seems like the launcher of different vendors are the one responsible for the badges in app icon in android. Sony Experia uses Experia Home/Launcher as its default launcher. in my sony device, they had some badge in there sms or miss calls or facebook.

现在的问题是:像previous的问题,有没有什么办法让知道Experia还家加徽章到我的应用程序图标

因为我想也许交互与发射看来这对添加徽章应用程序图标的解决方案。

because i was thinking maybe interacting with the launcher seems the solution of this "adding badge to app icon".

和有这种解决方案对本次活动的别名,并改变从时间的应用程序图标时,我认为是垃圾。 <一href="http://stackoverflow.com/questions/2905542/is-there-a-way-to-add-a-badge-to-an-application-icon-in-android">Is有没有办法徽章添加到Android的应用程序图标?

and there's this solution about this activity alias and changing the app icon from time to time which i think is rubbish. Is there a way to add a badge to an application icon in Android?

所以我在寻找解决方案,与它是特定于供应商的发射器进行交互。

so i'm seeking solution on interacting with the launchers which is vendor specific.

的任何解决方案将AP preciated甚至我会去深,使用原生开发的Andr​​oid

'any solution will be appreciated even i would go deep with using native development in android'

由于提前

推荐答案

我使用这个类的三星和索尼的设备(也可用的 https://gist.github.com/Tadas44/cdae2f5995f21bf1c27f )。不要忘记添加&LT;使用-权限的Andr​​oid:名称=com.sonyericsson.home.permission.BROADCAST_BADGE/&GT; 来的Andr​​oidManifest.xml

I use this class for Samsung and Sony devices (also available https://gist.github.com/Tadas44/cdae2f5995f21bf1c27f). Don't forget to add <uses-permission android:name="com.sonyericsson.home.permission.BROADCAST_BADGE" /> to AndroidManifest.xml

public class BadgeUtils {


    public static void setBadge(Context context, int count) {
        setBadgeSamsung(context, count);
        setBadgeSony(context, count);
    }

    public static void clearBadge(Context context) {
        setBadgeSamsung(context, 0);
        clearBadgeSony(context);
    }


    private static void setBadgeSamsung(Context context, int count) {
        String launcherClassName = getLauncherClassName(context);
        if (launcherClassName == null) {
            return;
        }
        Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
        intent.putExtra("badge_count", count);
        intent.putExtra("badge_count_package_name", context.getPackageName());
        intent.putExtra("badge_count_class_name", launcherClassName);
        context.sendBroadcast(intent);
    }

    private static void setBadgeSony(Context context, int count) {
        String launcherClassName = getLauncherClassName(context);
        if (launcherClassName == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction("com.sonyericsson.home.action.UPDATE_BADGE");
        intent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", launcherClassName);
        intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", true);
        intent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", String.valueOf(count));
        intent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", context.getPackageName());

        context.sendBroadcast(intent);
    }


    private static void clearBadgeSony(Context context) {
        String launcherClassName = getLauncherClassName(context);
        if (launcherClassName == null) {
            return;
        }

        Intent intent = new Intent();
        intent.setAction("com.sonyericsson.home.action.UPDATE_BADGE");
        intent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", launcherClassName);
        intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", false);
        intent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", String.valueOf(0));
        intent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", context.getPackageName());

        context.sendBroadcast(intent);
    }

    private static String getLauncherClassName(Context context) {

        PackageManager pm = context.getPackageManager();

        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);

        List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
        for (ResolveInfo resolveInfo : resolveInfos) {
            String pkgName = resolveInfo.activityInfo.applicationInfo.packageName;
            if (pkgName.equalsIgnoreCase(context.getPackageName())) {
                String className = resolveInfo.activityInfo.name;
                return className;
            }
        }
        return null;
    }
}

这篇关于添加通知徽章的Andr​​oid应用程序图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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