Set Drawable or Bitmap as icon In Notification in Android












15














I download a image from server as bitmap and convert it to drawable now i want to use this drawable as notification icon. But i am unable to do that. here is my code:



    Notification notification = new NotificationCompat.Builder(context)

.setContentTitle(title)

.setContentText(message)

.setContentIntent(intent)

.setSmallIcon(bitmap)

.setWhen(when)

.build();


but icon is a Resources int value so when i used it it gives error. Any help



Edit:



Now i update my code and now i am doing like that :



          Notification notification = new NotificationCompat.Builder(context)

.setContentTitle(title)

.setContentText(message)

.setContentIntent(intent)

.setSmallIcon(icon)

.setLargeIcon(bitmap)

.setWhen(when)

.build();


but it gives large icon on left side and small icon on right side. I don't want this so for this i remove setSmallIcon line and run my code but it not showing me the notifications










share|improve this question




















  • 1




    stackoverflow.com/a/16051724/931982 ... se my answer here
    – stinepike
    Apr 17 '13 at 8:23










  • thanks @StinePike see my edited question
    – User42590
    Apr 17 '13 at 8:31










  • lol for some reason i dont know why .. the small icon at the right side is called large icon .. only there you can set the bitmap. In higher api you can create your own notification with custom layout
    – stinepike
    Apr 17 '13 at 8:36










  • did you tried with this ? Notification notification = new Notification(R.drawable.logo,"App ", System.currentTimeMillis());
    – itsrajesh4uguys
    Apr 17 '13 at 8:36








  • 1




    may b 14 I am not sure .. please check
    – stinepike
    Apr 17 '13 at 8:39
















15














I download a image from server as bitmap and convert it to drawable now i want to use this drawable as notification icon. But i am unable to do that. here is my code:



    Notification notification = new NotificationCompat.Builder(context)

.setContentTitle(title)

.setContentText(message)

.setContentIntent(intent)

.setSmallIcon(bitmap)

.setWhen(when)

.build();


but icon is a Resources int value so when i used it it gives error. Any help



Edit:



Now i update my code and now i am doing like that :



          Notification notification = new NotificationCompat.Builder(context)

.setContentTitle(title)

.setContentText(message)

.setContentIntent(intent)

.setSmallIcon(icon)

.setLargeIcon(bitmap)

.setWhen(when)

.build();


but it gives large icon on left side and small icon on right side. I don't want this so for this i remove setSmallIcon line and run my code but it not showing me the notifications










share|improve this question




















  • 1




    stackoverflow.com/a/16051724/931982 ... se my answer here
    – stinepike
    Apr 17 '13 at 8:23










  • thanks @StinePike see my edited question
    – User42590
    Apr 17 '13 at 8:31










  • lol for some reason i dont know why .. the small icon at the right side is called large icon .. only there you can set the bitmap. In higher api you can create your own notification with custom layout
    – stinepike
    Apr 17 '13 at 8:36










  • did you tried with this ? Notification notification = new Notification(R.drawable.logo,"App ", System.currentTimeMillis());
    – itsrajesh4uguys
    Apr 17 '13 at 8:36








  • 1




    may b 14 I am not sure .. please check
    – stinepike
    Apr 17 '13 at 8:39














15












15








15


1





I download a image from server as bitmap and convert it to drawable now i want to use this drawable as notification icon. But i am unable to do that. here is my code:



    Notification notification = new NotificationCompat.Builder(context)

.setContentTitle(title)

.setContentText(message)

.setContentIntent(intent)

.setSmallIcon(bitmap)

.setWhen(when)

.build();


but icon is a Resources int value so when i used it it gives error. Any help



Edit:



Now i update my code and now i am doing like that :



          Notification notification = new NotificationCompat.Builder(context)

.setContentTitle(title)

.setContentText(message)

.setContentIntent(intent)

.setSmallIcon(icon)

.setLargeIcon(bitmap)

.setWhen(when)

.build();


but it gives large icon on left side and small icon on right side. I don't want this so for this i remove setSmallIcon line and run my code but it not showing me the notifications










share|improve this question















I download a image from server as bitmap and convert it to drawable now i want to use this drawable as notification icon. But i am unable to do that. here is my code:



    Notification notification = new NotificationCompat.Builder(context)

.setContentTitle(title)

.setContentText(message)

.setContentIntent(intent)

.setSmallIcon(bitmap)

.setWhen(when)

.build();


but icon is a Resources int value so when i used it it gives error. Any help



Edit:



Now i update my code and now i am doing like that :



          Notification notification = new NotificationCompat.Builder(context)

.setContentTitle(title)

.setContentText(message)

.setContentIntent(intent)

.setSmallIcon(icon)

.setLargeIcon(bitmap)

.setWhen(when)

.build();


but it gives large icon on left side and small icon on right side. I don't want this so for this i remove setSmallIcon line and run my code but it not showing me the notifications







android android-notifications android-notification-bar






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 2 '16 at 9:04









Parag Chauhan

27.4k137994




27.4k137994










asked Apr 17 '13 at 8:22









User42590User42590

1,27793473




1,27793473








  • 1




    stackoverflow.com/a/16051724/931982 ... se my answer here
    – stinepike
    Apr 17 '13 at 8:23










  • thanks @StinePike see my edited question
    – User42590
    Apr 17 '13 at 8:31










  • lol for some reason i dont know why .. the small icon at the right side is called large icon .. only there you can set the bitmap. In higher api you can create your own notification with custom layout
    – stinepike
    Apr 17 '13 at 8:36










  • did you tried with this ? Notification notification = new Notification(R.drawable.logo,"App ", System.currentTimeMillis());
    – itsrajesh4uguys
    Apr 17 '13 at 8:36








  • 1




    may b 14 I am not sure .. please check
    – stinepike
    Apr 17 '13 at 8:39














  • 1




    stackoverflow.com/a/16051724/931982 ... se my answer here
    – stinepike
    Apr 17 '13 at 8:23










  • thanks @StinePike see my edited question
    – User42590
    Apr 17 '13 at 8:31










  • lol for some reason i dont know why .. the small icon at the right side is called large icon .. only there you can set the bitmap. In higher api you can create your own notification with custom layout
    – stinepike
    Apr 17 '13 at 8:36










  • did you tried with this ? Notification notification = new Notification(R.drawable.logo,"App ", System.currentTimeMillis());
    – itsrajesh4uguys
    Apr 17 '13 at 8:36








  • 1




    may b 14 I am not sure .. please check
    – stinepike
    Apr 17 '13 at 8:39








1




1




stackoverflow.com/a/16051724/931982 ... se my answer here
– stinepike
Apr 17 '13 at 8:23




stackoverflow.com/a/16051724/931982 ... se my answer here
– stinepike
Apr 17 '13 at 8:23












thanks @StinePike see my edited question
– User42590
Apr 17 '13 at 8:31




thanks @StinePike see my edited question
– User42590
Apr 17 '13 at 8:31












lol for some reason i dont know why .. the small icon at the right side is called large icon .. only there you can set the bitmap. In higher api you can create your own notification with custom layout
– stinepike
Apr 17 '13 at 8:36




lol for some reason i dont know why .. the small icon at the right side is called large icon .. only there you can set the bitmap. In higher api you can create your own notification with custom layout
– stinepike
Apr 17 '13 at 8:36












did you tried with this ? Notification notification = new Notification(R.drawable.logo,"App ", System.currentTimeMillis());
– itsrajesh4uguys
Apr 17 '13 at 8:36






did you tried with this ? Notification notification = new Notification(R.drawable.logo,"App ", System.currentTimeMillis());
– itsrajesh4uguys
Apr 17 '13 at 8:36






1




1




may b 14 I am not sure .. please check
– stinepike
Apr 17 '13 at 8:39




may b 14 I am not sure .. please check
– stinepike
Apr 17 '13 at 8:39












4 Answers
4






active

oldest

votes


















23














If you read the developer documents specific to Notification.Builder you will see that setSmallIcon(int icon) needs a A resource ID in the application's package of the drawable to use.



Downloading an image, converting to a bitmap and then setting it to the setSmallIcon() is still going to give you an error.



Even if you were to convert the Bitmap to a Drawable like this for instance:



Drawable d = new BitmapDrawable(getResources(), bmpFinal);


it is still going to give you an error because that Drawable does not exist in your application package.



The only possible solution is to use a Drawable resource that exists in your package and set it to the setSmallIcon() method. Typical usage:



builder.setSmallIcon(R.drawable.ic_launcher);


Alternatively, the setLargeIcon (Bitmap icon) requires a Bitmap instance. Without having to make any additional changes in your current code (since you already have a Bitmap), you can use that as it is, if it fits your requirement.



If not, you pretty much have to use a Drawable resource that is already present in one of the drawable folders.






share|improve this answer

















  • 7




    setLargeIcon(Bitmap) doesn't work for me btw.
    – m0skit0
    Nov 3 '14 at 12:10



















15














you can try using this method



 builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));


http://javatechig.com/android/android-notification-example-using-notificationcompat






share|improve this answer

















  • 8




    This isn't answering what OP asked.
    – boltup_im_coding
    Jan 20 '16 at 18:44



















11














There is some points about this question, mainly related with API 23+, if you are only interested in setSmallIcon, go to the 2nd and 3rd topics.



1st :



You can set the LargeIcon from a Drawable (instead of Resource id), like the following



Drawable drawable= ContextCompat.getDrawable(this,R.drawable.your_drawable);

Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();

NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setLargeIcon(bitmap)
.setContentTitle("hahah")
.setContentText("Tap to stop")
.setOngoing(true);


2nd :



If you need to set a small icon in API below 23, you will need to set a resource id like R.drawable.your_resource.
The NotificationCompat.Builder does not allow you to use Drawables or Bitmaps in setSmallIcon().



3rd :



fortunately , the support has been expanded to Icon type on setSmallIcon() in version 23+, using the Notification.Builder, like following :



 Drawable drawable = ContextCompat.getDrawable(this,R.drawable.your_drawable);

Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();

Notification.Builder mBuilder =
new Notification.Builder(context)
.setSmallIcon(Icon.createWithBitmap(bitmap))
.setLargeIcon(bitmap)
.setContentTitle("hahah")
.setContentText("Tap to stop")
.setOngoing(true);





share|improve this answer



















  • 1




    Thanks for the last one, even though there's still no solution for old version.. Good to know anyways
    – Jenix
    Oct 18 '16 at 15:19



















3














Better option get application icon



 Drawable drawable=getApplicationInfo().loadIcon(getPackageManager());
Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();



.setSmallIcon(getApplicationInfo().icon)
.setLargeIcon(bitmap)





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16055073%2fset-drawable-or-bitmap-as-icon-in-notification-in-android%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    23














    If you read the developer documents specific to Notification.Builder you will see that setSmallIcon(int icon) needs a A resource ID in the application's package of the drawable to use.



    Downloading an image, converting to a bitmap and then setting it to the setSmallIcon() is still going to give you an error.



    Even if you were to convert the Bitmap to a Drawable like this for instance:



    Drawable d = new BitmapDrawable(getResources(), bmpFinal);


    it is still going to give you an error because that Drawable does not exist in your application package.



    The only possible solution is to use a Drawable resource that exists in your package and set it to the setSmallIcon() method. Typical usage:



    builder.setSmallIcon(R.drawable.ic_launcher);


    Alternatively, the setLargeIcon (Bitmap icon) requires a Bitmap instance. Without having to make any additional changes in your current code (since you already have a Bitmap), you can use that as it is, if it fits your requirement.



    If not, you pretty much have to use a Drawable resource that is already present in one of the drawable folders.






    share|improve this answer

















    • 7




      setLargeIcon(Bitmap) doesn't work for me btw.
      – m0skit0
      Nov 3 '14 at 12:10
















    23














    If you read the developer documents specific to Notification.Builder you will see that setSmallIcon(int icon) needs a A resource ID in the application's package of the drawable to use.



    Downloading an image, converting to a bitmap and then setting it to the setSmallIcon() is still going to give you an error.



    Even if you were to convert the Bitmap to a Drawable like this for instance:



    Drawable d = new BitmapDrawable(getResources(), bmpFinal);


    it is still going to give you an error because that Drawable does not exist in your application package.



    The only possible solution is to use a Drawable resource that exists in your package and set it to the setSmallIcon() method. Typical usage:



    builder.setSmallIcon(R.drawable.ic_launcher);


    Alternatively, the setLargeIcon (Bitmap icon) requires a Bitmap instance. Without having to make any additional changes in your current code (since you already have a Bitmap), you can use that as it is, if it fits your requirement.



    If not, you pretty much have to use a Drawable resource that is already present in one of the drawable folders.






    share|improve this answer

















    • 7




      setLargeIcon(Bitmap) doesn't work for me btw.
      – m0skit0
      Nov 3 '14 at 12:10














    23












    23








    23






    If you read the developer documents specific to Notification.Builder you will see that setSmallIcon(int icon) needs a A resource ID in the application's package of the drawable to use.



    Downloading an image, converting to a bitmap and then setting it to the setSmallIcon() is still going to give you an error.



    Even if you were to convert the Bitmap to a Drawable like this for instance:



    Drawable d = new BitmapDrawable(getResources(), bmpFinal);


    it is still going to give you an error because that Drawable does not exist in your application package.



    The only possible solution is to use a Drawable resource that exists in your package and set it to the setSmallIcon() method. Typical usage:



    builder.setSmallIcon(R.drawable.ic_launcher);


    Alternatively, the setLargeIcon (Bitmap icon) requires a Bitmap instance. Without having to make any additional changes in your current code (since you already have a Bitmap), you can use that as it is, if it fits your requirement.



    If not, you pretty much have to use a Drawable resource that is already present in one of the drawable folders.






    share|improve this answer












    If you read the developer documents specific to Notification.Builder you will see that setSmallIcon(int icon) needs a A resource ID in the application's package of the drawable to use.



    Downloading an image, converting to a bitmap and then setting it to the setSmallIcon() is still going to give you an error.



    Even if you were to convert the Bitmap to a Drawable like this for instance:



    Drawable d = new BitmapDrawable(getResources(), bmpFinal);


    it is still going to give you an error because that Drawable does not exist in your application package.



    The only possible solution is to use a Drawable resource that exists in your package and set it to the setSmallIcon() method. Typical usage:



    builder.setSmallIcon(R.drawable.ic_launcher);


    Alternatively, the setLargeIcon (Bitmap icon) requires a Bitmap instance. Without having to make any additional changes in your current code (since you already have a Bitmap), you can use that as it is, if it fits your requirement.



    If not, you pretty much have to use a Drawable resource that is already present in one of the drawable folders.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Apr 17 '13 at 8:38









    Siddharth LeleSiddharth Lele

    24.1k1379137




    24.1k1379137








    • 7




      setLargeIcon(Bitmap) doesn't work for me btw.
      – m0skit0
      Nov 3 '14 at 12:10














    • 7




      setLargeIcon(Bitmap) doesn't work for me btw.
      – m0skit0
      Nov 3 '14 at 12:10








    7




    7




    setLargeIcon(Bitmap) doesn't work for me btw.
    – m0skit0
    Nov 3 '14 at 12:10




    setLargeIcon(Bitmap) doesn't work for me btw.
    – m0skit0
    Nov 3 '14 at 12:10













    15














    you can try using this method



     builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));


    http://javatechig.com/android/android-notification-example-using-notificationcompat






    share|improve this answer

















    • 8




      This isn't answering what OP asked.
      – boltup_im_coding
      Jan 20 '16 at 18:44
















    15














    you can try using this method



     builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));


    http://javatechig.com/android/android-notification-example-using-notificationcompat






    share|improve this answer

















    • 8




      This isn't answering what OP asked.
      – boltup_im_coding
      Jan 20 '16 at 18:44














    15












    15








    15






    you can try using this method



     builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));


    http://javatechig.com/android/android-notification-example-using-notificationcompat






    share|improve this answer












    you can try using this method



     builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));


    http://javatechig.com/android/android-notification-example-using-notificationcompat







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Sep 27 '15 at 23:03









    Remon AminRemon Amin

    7531136




    7531136








    • 8




      This isn't answering what OP asked.
      – boltup_im_coding
      Jan 20 '16 at 18:44














    • 8




      This isn't answering what OP asked.
      – boltup_im_coding
      Jan 20 '16 at 18:44








    8




    8




    This isn't answering what OP asked.
    – boltup_im_coding
    Jan 20 '16 at 18:44




    This isn't answering what OP asked.
    – boltup_im_coding
    Jan 20 '16 at 18:44











    11














    There is some points about this question, mainly related with API 23+, if you are only interested in setSmallIcon, go to the 2nd and 3rd topics.



    1st :



    You can set the LargeIcon from a Drawable (instead of Resource id), like the following



    Drawable drawable= ContextCompat.getDrawable(this,R.drawable.your_drawable);

    Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();

    NotificationCompat.Builder mBuilder =
    new NotificationCompat.Builder(context)
    .setLargeIcon(bitmap)
    .setContentTitle("hahah")
    .setContentText("Tap to stop")
    .setOngoing(true);


    2nd :



    If you need to set a small icon in API below 23, you will need to set a resource id like R.drawable.your_resource.
    The NotificationCompat.Builder does not allow you to use Drawables or Bitmaps in setSmallIcon().



    3rd :



    fortunately , the support has been expanded to Icon type on setSmallIcon() in version 23+, using the Notification.Builder, like following :



     Drawable drawable = ContextCompat.getDrawable(this,R.drawable.your_drawable);

    Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();

    Notification.Builder mBuilder =
    new Notification.Builder(context)
    .setSmallIcon(Icon.createWithBitmap(bitmap))
    .setLargeIcon(bitmap)
    .setContentTitle("hahah")
    .setContentText("Tap to stop")
    .setOngoing(true);





    share|improve this answer



















    • 1




      Thanks for the last one, even though there's still no solution for old version.. Good to know anyways
      – Jenix
      Oct 18 '16 at 15:19
















    11














    There is some points about this question, mainly related with API 23+, if you are only interested in setSmallIcon, go to the 2nd and 3rd topics.



    1st :



    You can set the LargeIcon from a Drawable (instead of Resource id), like the following



    Drawable drawable= ContextCompat.getDrawable(this,R.drawable.your_drawable);

    Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();

    NotificationCompat.Builder mBuilder =
    new NotificationCompat.Builder(context)
    .setLargeIcon(bitmap)
    .setContentTitle("hahah")
    .setContentText("Tap to stop")
    .setOngoing(true);


    2nd :



    If you need to set a small icon in API below 23, you will need to set a resource id like R.drawable.your_resource.
    The NotificationCompat.Builder does not allow you to use Drawables or Bitmaps in setSmallIcon().



    3rd :



    fortunately , the support has been expanded to Icon type on setSmallIcon() in version 23+, using the Notification.Builder, like following :



     Drawable drawable = ContextCompat.getDrawable(this,R.drawable.your_drawable);

    Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();

    Notification.Builder mBuilder =
    new Notification.Builder(context)
    .setSmallIcon(Icon.createWithBitmap(bitmap))
    .setLargeIcon(bitmap)
    .setContentTitle("hahah")
    .setContentText("Tap to stop")
    .setOngoing(true);





    share|improve this answer



















    • 1




      Thanks for the last one, even though there's still no solution for old version.. Good to know anyways
      – Jenix
      Oct 18 '16 at 15:19














    11












    11








    11






    There is some points about this question, mainly related with API 23+, if you are only interested in setSmallIcon, go to the 2nd and 3rd topics.



    1st :



    You can set the LargeIcon from a Drawable (instead of Resource id), like the following



    Drawable drawable= ContextCompat.getDrawable(this,R.drawable.your_drawable);

    Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();

    NotificationCompat.Builder mBuilder =
    new NotificationCompat.Builder(context)
    .setLargeIcon(bitmap)
    .setContentTitle("hahah")
    .setContentText("Tap to stop")
    .setOngoing(true);


    2nd :



    If you need to set a small icon in API below 23, you will need to set a resource id like R.drawable.your_resource.
    The NotificationCompat.Builder does not allow you to use Drawables or Bitmaps in setSmallIcon().



    3rd :



    fortunately , the support has been expanded to Icon type on setSmallIcon() in version 23+, using the Notification.Builder, like following :



     Drawable drawable = ContextCompat.getDrawable(this,R.drawable.your_drawable);

    Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();

    Notification.Builder mBuilder =
    new Notification.Builder(context)
    .setSmallIcon(Icon.createWithBitmap(bitmap))
    .setLargeIcon(bitmap)
    .setContentTitle("hahah")
    .setContentText("Tap to stop")
    .setOngoing(true);





    share|improve this answer














    There is some points about this question, mainly related with API 23+, if you are only interested in setSmallIcon, go to the 2nd and 3rd topics.



    1st :



    You can set the LargeIcon from a Drawable (instead of Resource id), like the following



    Drawable drawable= ContextCompat.getDrawable(this,R.drawable.your_drawable);

    Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();

    NotificationCompat.Builder mBuilder =
    new NotificationCompat.Builder(context)
    .setLargeIcon(bitmap)
    .setContentTitle("hahah")
    .setContentText("Tap to stop")
    .setOngoing(true);


    2nd :



    If you need to set a small icon in API below 23, you will need to set a resource id like R.drawable.your_resource.
    The NotificationCompat.Builder does not allow you to use Drawables or Bitmaps in setSmallIcon().



    3rd :



    fortunately , the support has been expanded to Icon type on setSmallIcon() in version 23+, using the Notification.Builder, like following :



     Drawable drawable = ContextCompat.getDrawable(this,R.drawable.your_drawable);

    Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();

    Notification.Builder mBuilder =
    new Notification.Builder(context)
    .setSmallIcon(Icon.createWithBitmap(bitmap))
    .setLargeIcon(bitmap)
    .setContentTitle("hahah")
    .setContentText("Tap to stop")
    .setOngoing(true);






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 28 '18 at 9:45









    KGCybeX

    815939




    815939










    answered Jul 29 '16 at 10:40









    Lucas PaolilloLucas Paolillo

    3,30211221




    3,30211221








    • 1




      Thanks for the last one, even though there's still no solution for old version.. Good to know anyways
      – Jenix
      Oct 18 '16 at 15:19














    • 1




      Thanks for the last one, even though there's still no solution for old version.. Good to know anyways
      – Jenix
      Oct 18 '16 at 15:19








    1




    1




    Thanks for the last one, even though there's still no solution for old version.. Good to know anyways
    – Jenix
    Oct 18 '16 at 15:19




    Thanks for the last one, even though there's still no solution for old version.. Good to know anyways
    – Jenix
    Oct 18 '16 at 15:19











    3














    Better option get application icon



     Drawable drawable=getApplicationInfo().loadIcon(getPackageManager());
    Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();



    .setSmallIcon(getApplicationInfo().icon)
    .setLargeIcon(bitmap)





    share|improve this answer


























      3














      Better option get application icon



       Drawable drawable=getApplicationInfo().loadIcon(getPackageManager());
      Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();



      .setSmallIcon(getApplicationInfo().icon)
      .setLargeIcon(bitmap)





      share|improve this answer
























        3












        3








        3






        Better option get application icon



         Drawable drawable=getApplicationInfo().loadIcon(getPackageManager());
        Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();



        .setSmallIcon(getApplicationInfo().icon)
        .setLargeIcon(bitmap)





        share|improve this answer












        Better option get application icon



         Drawable drawable=getApplicationInfo().loadIcon(getPackageManager());
        Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();



        .setSmallIcon(getApplicationInfo().icon)
        .setLargeIcon(bitmap)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jul 27 '17 at 6:23









        Neeraj SinghNeeraj Singh

        674513




        674513






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16055073%2fset-drawable-or-bitmap-as-icon-in-notification-in-android%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas

            Can't read property showImagePicker of undefined in react native iOS