Drawable Object Parameter Pass

0

I've created a method to encapsulate a notification message (% with%). An excerpt of the code is shown below:

 public void exibirMensagem(String titulo, String texto,Drawable icone)
{
    Notification.Builder mensagem = new Notification.Builder(contexto)
             //TROCAR PARA O ÍCONE PADRÃO DA APLICACAO
            .setSmallIcon(icone);}

It turns out that the Notification.Builder method does not accept the icone object that was passed by parameter. icone is underlined in red and when I pass the mouse cursor the following message appears:

  Can not resolved method   'setSmallIcon (android.graphics.drawable.Drawable

How can I solve this, ie pass a Drawable as a parameter and use in the .setSmallIcone method?

    
asked by anonymous 17.03.2017 / 00:57

1 answer

3

According to the documentation , the parameter that should be passed to setSmallICon is a Int instead of a Drawable .

So your code should look like this:

public void exibirMensagem(String titulo, String texto, int icone)
{
    Notification.Builder mensagem = new Notification.Builder(contexto)
         //TROCAR PARA O ÍCONE PADRÃO DA APLICACAO
        .setSmallIcon(icone);
}
  

How to use the above code?

// FloatingActionButton -> OnClickListener...
exibirMensagem("hello world", "Hello world is so nice, guys!", R.drawable.ic_hello_app);
    
17.03.2017 / 03:52