2013-09-30 132 views
5

您可能認爲這是一個重複的問題,但我想要的答案比任何類似的問題都更具體。在android的應用程序圖標上添加通知徽章

首先它說像Facebook有三星設備通知徽章。 How does Facebook add badge numbers on app icon in Android?。它變成了可能是三星設備的默認啓動器的touchwiz啓動器。當我試圖用新星發射器測試我的三星設備時。它需要安裝一些第三方軟件或Nova TestlaUnread。這是事實。我認爲touchWiz會爲所有應用程序添加徽章,但是當我嘗試使用我的應用程序進行測試以獲得某些通知時,它不會顯示任何徽章。因爲我發現,三星的TouchWiz只顯示爲說明此應用到所選的應用: UI help for Notification on icon

The question is: is there any way to let know the touchWiz to add badge to my app-icon? 這對三星設備,

與以前的論點,好像不同廠商的發射是一個負責android中應用程序圖標中的徽章。索尼Experia使用Experia Home/Launcher作爲默認啓動程序。在我的索尼設備中,他們在那裏有一些徽章或短信電話或Facebook。

The question is: like the previous question, is there any way to let know experia home to add badge to my app icon?

,因爲我想也許與發射器進行交互看來這「添加徽章應用程序圖標」的解決方案。

並且有關於此活動別名的此解決方案並不時更改我認爲是垃圾的應用程序圖標。 Is there a way to add a badge to an application icon in Android?

所以我正在尋求解決方案與供應商特定的發射器進行交互。

「的任何解決方案將甚至讚賞我會在Android的使用本地發展的堅定走」提前

+0

是的,我已經寫了一個如何,到了這裏http://stackoverflow.com/questions/20136483/how-do-you-interface-with-badgeprovider -on-samsung-phones/20136484#20136484 –

+0

[有沒有方法可以將徽章添加到Android中的應用程序圖標?](https://stackoverflow.com/questions/2905542/is-there-a-在Android中添加徽章到應用程序圖標的方式) –

回答

0

由於除了丹尼爾·奧查婭的三星解決方案(見OP評論),我已經想通了解如何爲索尼設備完成此操作。我的博客here。我還發布了一個關於此here的單獨SO問題。


索尼設備使用名爲BadgeReciever的類。

  1. 聲明com.sonyericsson.home.permission.BROADCAST_BADGE許可清單檔案中的:

  2. 廣播的IntentBadgeReceiver

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

我已經排除我如何發現這個細節讓答案短,但它在博客中都可用。可能是一個有趣的閱讀某人。

+0

由於此問題沒有答案,而且您沒有代表,所以我不打算標記這一點(我已給您回答審查)。我建議你用這些鏈接中的一些相關信息填充問題。我已經投了你的其他問題,所以你可以回答它。 – OGHaza

+0

謝謝@OGHaza。我已經爲這個答案添加了一些代碼,現在將回答我的主要問題。 – Marcus

+0

我會試試這個。謝謝.. – Vik2r

4

我使用這個類的三星和索尼設備(也可用https://gist.github.com/Tadas44/cdae2f5995f21bf1c27f)。不要忘記添加<uses-permission android:name="com.sonyericsson.home.permission.BROADCAST_BADGE" />到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; 
    } 
} 
+1

在我的情況下,它適用於三星設備,但現在它似乎只適用於三星和索尼設備。所以,我們需要更新這個答案,以使其能夠爲其他製造商工作。 – Harpreet

相關問題