Add badge icon in Application Icon in Android

I'm new in xamarin.Forms and I need to add a badge icon to show total number of notification over application icon in android platform.

Can any please provide solution for it?

Posts

  • StasPetrovStasPetrov UAMember ✭✭

    I found that there isn't "universal" solution to do this. Then I found good java library on github, now I ported some part of this lib to c# (badge for asus, LG and xaomi launchers) I need little bit more time to complete it. I will make nuget package, publish it and post link for you.

  • YkshLeoYkshLeo USMember ✭✭✭✭

    @xamarinbeginner

    You can do it by a java library : https://github.com/jgilfelt/android-viewbadger

    Include this library in to your project : https://developer.xamarin.com/guides/android/advanced_topics/java_integration_overview/binding-a-java-library/

    View target = FindViewById<View>(Resource.Id.target_view); BadgeView badge = new BadgeView(this, target); badge.setText("1"); badge.show();

  • jariwalahetaljariwalahetal USMember ✭✭

    @Yksh.Leo
    The links you have provided does not worked for me :(

    Here I want to clarify that i need badge icon on icon on menu in mobile not under the application

  • RaphicRaphic USMember
    edited February 2016

    Hi All ,
    I m using BadgeView like Below

    ImageView imgInfoFollow = popupView.FindViewById<ImageView>(Resource.Id.infoFollow);
    BadgeView badgeInfoFollow = new BadgeView(this, imgInfoFollow);
    badgeInfoFollow.SetText(1);
    badgeInfoFollow.Show();
    

    i am getting Below Error

    {Android.Content.Res.Resources+NotFoundException: Exception of type 'Android.Content.Res.Resources+NotFoundException' was thrown.
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in <filename unknown>:0 
      at Android.Runtime.JNIEnv.CallVoidMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00063] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:571 
      at Android.Widget.TextView.SetText (Int32 resid) [0x00044] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Widget.TextView.cs:6650 
      at PoliciaPopular.GooglePlaces.Map_MarkerClick (System.Object sender, Android.Gms.Maps.MarkerClickEventArgs e) [0x000b6] in C:\Users\rafiq\Documents\Visual Studio 2015\Projects\PoliciaPopular\PoliciaPopular\GooglePlaces.cs:380 
      --- End of managed exception stack trace ---
    android.content.res.Resources$NotFoundException: String resource ID #0x1
        at android.content.res.Resources.getText(Resources.java:1419)
        at android.widget.TextView.setText(TextView.java:4947)
        at mono.com.google.android.gms.maps.GoogleMap_OnMarkerClickListenerImplementor.n_onMarkerClick(Native Method)
        at mono.com.google.android.gms.maps.GoogleMap_OnMarkerClickListenerImplementor.onMarkerClick(GoogleMap_OnMarkerClickListenerImplementor.java:29)
        at com.google.android.gms.maps.GoogleMap$10.zza(Unknown Source)
        at com.google.android.gms.maps.internal.zzn$zza.onTransact(Unknown Source)
        at android.os.Binder.transact(Binder.java:361)
        at com.google.android.gms.maps.internal.ay.a(SourceFile:84)
        at com.google.maps.api.android.lib6.d.ai.b(Unknown Source)
        at com.google.maps.api.android.lib6.gmm6.c.e.a(Unknown Source)
        at com.google.maps.api.android.lib6.gmm6.n.av.a(Unknown Source)
        at com.google.maps.api.android.lib6.gmm6.n.be.a(Unknown Source)
        at com.google.maps.api.android.lib6.gmm6.n.bd.a(Unknown Source)
        at com.google.maps.api.android.lib6.gmm6.n.bw.d(Unknown Source)
        at com.google.maps.api.android.lib6.gmm6.n.ak.onSingleTapConfirmed(Unknown Source)
        at com.google.maps.api.android.lib6.gmm6.h.g.onSingleTapConfirmed(Unknown Source)
        at com.google.maps.api.android.lib6.gmm6.h.i.handleMessage(Unknown Source)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:146)
        at android.app.ActivityThread.main(ActivityThread.java:5602)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
        at dalvik.system.NativeStart.main(Native Method)
    }
    

    Please Somebody help me with this, I'm stuck with my project

  • adithyavarmaadithyavarma USMember

    still did any one could achieve it for ..... AppIcon ?

    I need to display the number of pending notifications on app icon ! not in views -_- !

    So please if anyone knows the solution ...... can help out :smile:

    Thanx in advance

  • jariwalahetaljariwalahetal USMember ✭✭

    @adithyavarma

    Yes i'm able to achieve that in android devices, but there is no universal support for it

  • adithyavarmaadithyavarma USMember

    can please guide me or refer me a tutorial on how to achieve it ? @xamarinbeginner
    Please i wud b v.thankful to yu....plz !

  • Chris_LamontChris_Lamont USUniversity ✭✭

    Has anyone tried this package?

    https://www.nuget.org/packages/Xam.Plugin.Badge/

  • Someone with ANY SOLUTION?

  • jariwalahetaljariwalahetal USMember ✭✭

    @Chris_Lamont

    The link you provided works on badge icon in app and here i'm considering badge icon on app's icon like in iOs

  • @Raphic said:
    Hi All ,
    I m using BadgeView like Below

    ImageView imgInfoFollow = popupView.FindViewById<ImageView>(Resource.Id.infoFollow);
    BadgeView badgeInfoFollow = new BadgeView(this, imgInfoFollow);
    badgeInfoFollow.SetText(1);
    badgeInfoFollow.Show();
    

    i am getting Below Error

    {Android.Content.Res.Resources+NotFoundException: Exception of type 'Android.Content.Res.Resources+NotFoundException' was thrown.
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in <filename unknown>:0 
      at Android.Runtime.JNIEnv.CallVoidMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00063] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:571 
      at Android.Widget.TextView.SetText (Int32 resid) [0x00044] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Widget.TextView.cs:6650 
      at PoliciaPopular.GooglePlaces.Map_MarkerClick (System.Object sender, Android.Gms.Maps.MarkerClickEventArgs e) [0x000b6] in C:\Users\rafiq\Documents\Visual Studio 2015\Projects\PoliciaPopular\PoliciaPopular\GooglePlaces.cs:380 
      --- End of managed exception stack trace ---
    android.content.res.Resources$NotFoundException: String resource ID #0x1
      at android.content.res.Resources.getText(Resources.java:1419)
      at android.widget.TextView.setText(TextView.java:4947)
      at mono.com.google.android.gms.maps.GoogleMap_OnMarkerClickListenerImplementor.n_onMarkerClick(Native Method)
      at mono.com.google.android.gms.maps.GoogleMap_OnMarkerClickListenerImplementor.onMarkerClick(GoogleMap_OnMarkerClickListenerImplementor.java:29)
      at com.google.android.gms.maps.GoogleMap$10.zza(Unknown Source)
      at com.google.android.gms.maps.internal.zzn$zza.onTransact(Unknown Source)
      at android.os.Binder.transact(Binder.java:361)
      at com.google.android.gms.maps.internal.ay.a(SourceFile:84)
      at com.google.maps.api.android.lib6.d.ai.b(Unknown Source)
      at com.google.maps.api.android.lib6.gmm6.c.e.a(Unknown Source)
      at com.google.maps.api.android.lib6.gmm6.n.av.a(Unknown Source)
      at com.google.maps.api.android.lib6.gmm6.n.be.a(Unknown Source)
      at com.google.maps.api.android.lib6.gmm6.n.bd.a(Unknown Source)
      at com.google.maps.api.android.lib6.gmm6.n.bw.d(Unknown Source)
      at com.google.maps.api.android.lib6.gmm6.n.ak.onSingleTapConfirmed(Unknown Source)
      at com.google.maps.api.android.lib6.gmm6.h.g.onSingleTapConfirmed(Unknown Source)
      at com.google.maps.api.android.lib6.gmm6.h.i.handleMessage(Unknown Source)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:146)
      at android.app.ActivityThread.main(ActivityThread.java:5602)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:515)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
      at dalvik.system.NativeStart.main(Native Method)
    }
    

    Please Somebody help me with this, I'm stuck with my project

    Maybe, I'm not sure

    badgeInfoFollow.SetText("Text here, not an integer");

  • RaphicRaphic USMember

    @MarcoSeraphin

    ImageView imgInfoFollow = popupView.FindViewById(Resource.Id.infoFollow);
    BadgeView badgeInfoFollow = new BadgeView(this, imgInfoFollow);
    badgeInfoFollow.SetText="1";
    badgeInfoFollow.Show();

    it worked for me

  • @Vaikesh K P,

    I used Xam.Plugin.Badge to show badge count in Android, but instead of showing count on app icon, it is showing it as notification.

    Is it possible to show above app icon as iOS does?

    Please respond once you see this...

  • jariwalahetaljariwalahetal USMember ✭✭

    @SubhaMuralidharan.6484, I have also used the plugin you mention but it is not workinng.

    Follow the below link for the solution
    http://hetaljariwala.blogspot.in/2016/02/ios-style-badge-icon-in-android-app.html

    Do message me if you find any difficulty.

  • SubhaMuralidharan.6484SubhaMuralidharan.6484 USMember
    edited May 2016

    @xamarinbeginner

    Thanks for your answer. I need to show badge icon in all Android devices, link you have referenced is for only few devices right? What about BadgeView? Will that work?

    Right now, I don't know how to get application icon using FindViewById? I want to show badge count on application icon similar to iOS.

  • jariwalahetaljariwalahetal USMember ✭✭

    @SubhaMuralidharan.6484 iOS style badges are not supported in Android. There is manufacturer level implementation for badge in android. So I have used that methods here.

    There is no universal support of badge on app icon for android.

    If you find any other information regarding it. Please do post it here.

  • ShrutiJoshiShrutiJoshi USMember
    edited December 2016

    Hello All,

    I am using Shortcutbadger from https://github.com/neurospeech/xamarin-shortcut-badger , I am able to display the badge number in Samsung mobiles.

    I want to execute the same on Nexus as well. Do I need to register any permission for Nexus in Manifest files?

    I have already added permissions in the Manifest files for Samsung,HTC,Sony,Apex,Solid,Huawei,ZUK,OPPO.

    Please help.

    Thank you

  • jariwalahetaljariwalahetal USMember ✭✭

    @ShrutiJoshi

    Yes for each platform you need to specify permission.

  • ShrutiJoshiShrutiJoshi USMember

    @Hetal.H.Jariwala Can I please know which permission I need to set in the Manifest file for Nexus devices?

  • jariwalahetaljariwalahetal USMember ✭✭

    I afraid I'm not aware about it.

  • pnet1pnet1 USMember ✭✭✭✭

    @Raphic, how can i implement that code posted above for you? Where do i implement? Can you post all solution to show the icon when we receive push notification?

  • pnet1pnet1 USMember ✭✭✭✭

    @Hetal.H.Jariwala, i'm not getting to implement the code that you posted in your blog.

  • jariwalahetaljariwalahetal USMember ✭✭

    @pnet1 What error you are getting?

  • pnet1pnet1 USMember ✭✭✭✭
    edited October 2017

    @Hetal.H.Jariwala, I don't getting to implement. For example: You said that we must to create a abstract class, but where? In the PCL or Android project? I downloaded your project and is running fine, but the examples are tab and how can i do to show the icon over my App icon? These are some doubt. There are more. You created the SamsungHomeBadger class, but does it inherit of who? Because there is: :base(context). I'm learning Xamarin. These example i saw here

  • jariwalahetaljariwalahetal USMember ✭✭

    @pnet1
    It should be in Android project

  • pnet1pnet1 USMember ✭✭✭✭
    edited October 2017

    @Hetal.H.Jariwala, i still waiting for your solution. Please, if you can help me, i'm thankfull.

  • jariwalahetaljariwalahetal USMember ✭✭

    @pnet1 I have update the demo here which I have tested in Android.
    Hope it will help you.

    https://drive.google.com/file/d/0B0dJLMU9SXZHZk4wTUp0N1N5NDQ/view?usp=sharing

  • saishaiksaishaik INMember ✭✭

    @Hetal.H.Jariwala ,i added Badge,MyBadge Classes and all the classees as in implementation folder adne added Badge badge = new Badge(this); badge.count(50) in mainActivity; as in your blog but iam not getting the badge on app icon ,still anything to add to get badge on icon?

  • jariwalahetaljariwalahetal USMember ✭✭

    @saishaik
    Have you inserted permissions in manifest file?
    There is demo attached in blog so you can check it there

  • saishaiksaishaik INMember ✭✭

    @Hetal.H.Jariwala ,I added permissions in manifest and added all the classes that you mentioned in demo but not getting.

  • saishaiksaishaik INMember ✭✭
    edited October 2017

    public MyBadge getBadger(Context context)
    {
    if (mBadge != null)
    {
    return mBadge;
    }
    Log.Debug(LOG_TAG, "Finding badger");

            try
            {
                Intent intent = new Intent(Intent.ActionMain);
                intent.AddCategory(Intent.CategoryHome);
                ResolveInfo resolveInfo = context.PackageManager.ResolveActivity(intent, PackageInfoFlags.MatchDefaultOnly);
                String currentHomePackage = resolveInfo.ActivityInfo.PackageName.ToLower();
    
                /*if (Build.Manufacturer.ToLower() == "xiaomi") {
                    mBadge = new XiaomiHomeBadger(context);
                    return mBadge;
                }*/
    
                foreach (string badgeclass in BADGERS)
                {
                    Type t = Type.GetType("MyApp.Android." + badgeclass);
                    MyBadge myObject = (MyBadge)Activator.CreateInstance(t, new Object[] { context });
                    if (myObject.getSupportLaunchers().Contains(currentHomePackage))
                    {
                        mBadge = myObject;
                    }
                }
            }
    

    here iam getting "t" as null and currentHomePackage as "com.android.launcher3" while iam running this for samsung device in genymotion.

  • jariwalahetaljariwalahetal USMember ✭✭
Sign In or Register to comment.