Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Notification Icon not display properly Xamarin Android

$
0
0

I have problem setting up a notification image to display properly.

Below is the original image, with file path:

myApp\Resources\drawable\Icon.png

Dimensions: 72x72pixels, 32bit depths

enter image description here

The problem:

It displays like below.

enter image description here

Below is the code. The code seems working correctly for previous version which displays it properly.

 public class MyServiceConnection : Java.Lang.Object, IServiceConnection
    {
        private string _appName;

        public MyServiceConnection(string appName)
        {
            _appName = appName;
        }

        public void OnServiceConnected(ComponentName name, IBinder service)
        {
 var intent = new Intent(Application.Context, typeof(ManifestActivity));
            intent.AddFlags(ActivityFlags.ClearTop);
            var pendingIntent = PendingIntent.GetActivity(Application.Context, 0, intent, PendingIntentFlags.UpdateCurrent);

            var notificationBuilder = new NotificationCompat.Builder(Application.Context)

                .SetSmallIcon(Resource.Drawable.Icon)
                .SetContentTitle(_appName)
                .SetAutoCancel(true)
                .SetContentIntent(pendingIntent);

            var notificationManager = NotificationManager.FromContext(Application.Context);
            var notification = notificationBuilder.Build();
            notificationManager.Notify(1, notification);

            var serviceBinder = service as MyService.Binder;
            serviceBinder.StartForeground(1, notification);
    }

    public void OnServiceDisconnected(ComponentName name)
        {
        }
}

Envoironments:

 android:minSdkVersion="15" android:targetSdkVersion="27" 

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>