【问题标题】:How to achieve push notification badge in android for all devices如何在android中为所有设备实现推送通知徽章
【发布时间】:2014-03-05 08:48:03
【问题描述】:

我想在三星、索尼、LG 等所有设备上显示推送通知徽章,我想像 facebook 原生应用程序一样显示通知徽章。我为此做了一些小研究,结果Android依靠通知中心向用户提供有关传入事件的指示。所以从技术上讲,如果您的应用程序已经这样做了,那么您无需执行任何其他操作。 但有些设备有自己的框架徽章接收器。

在索尼

http://marcusforsberg.net/blog/android-notification-badge-app-icon-sony/

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

在三星

https://github.com/shafty023/SamsungBadger

将以下权限添加到应用程序的 AndroidManifest.xml

uses-permission android:name="com.sec.android.provider.badge.permission.READ" 
uses-permission android:name="com.sec.android.provider.badge.permission.WRITE" 

用“1”标记你的图标

Context context = getApplicationContext();
if (Badge.isBadgingSupported(context)) {
    Badge badge = new Badge();
    badge.mPackage = context.getPackageName();
    badge.mClass = getClass().getName();
    badge.mBadgeCount = 1;
    badge.save(context);
}

是否有其他可用的框架徽章接收器代码?

【问题讨论】:

  • 为什么要复制iOS的UI?请尝试发明一些新的东西。
  • @Raptor:是的,你是对的,但有些用户希望发布与 iOS 相同的 UI。他们告诉 facebook 原生应用程序有徽章为什么我们的应用程序不能这样做。对不起我的英语不好。
  • Facebook 原生应用是否有适用于所有 Android 设备和启动器的徽章?
  • 不,它没有,但有些设备具有该功能。
  • 你有什么解决办法吗?

标签: android push-notification badge


【解决方案1】:

我也遇到了同样的问题,但您的问题的完美解决方案如下链接:

https://derivedcode.wordpress.com/2013/10/09/showing-badge-or-count-in-android-app-icon/

【讨论】:

  • 链接是正确的,似乎是准确的解决方案......谢谢@androiddeveloper2011
【解决方案2】:

尝试使用这个库ShortcutBadger

来自github的描述:

ShortcutBadger:ShortcutBadger 使您的 Android 应用程序显示 作为应用快捷方式标记的未读消息计数!

【讨论】:

【解决方案3】:

这对我有用:

1) Add mavenCentral to your build script.

 repositories {
    mavenCentral()
}

2) Add dependencies for ShortcutBadger, it's available from maven now.

 dependencies {
        compile 'me.leolin:ShortcutBadger:1.1.4@aar'
    }

3) Add the codes below:

int badgeCount = 1;
ShortcutBadger.applyCount(context, badgeCount); //for 1.1.4
ShortcutBadger.with(getApplicationContext()).count(badgeCount); //for 1.1.3

4) If you want to remove the badge
 ShortcutBadger.removeCount(context); //for 1.1.4
ShortcutBadger.with(getApplicationContext()).remove();  //for 1.1.3

 or

ShortcutBadger.applyCount(context, 0); //for 1.1.4
ShortcutBadger.with(getApplicationContext()).count(0); //for 1.1.3

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多