Search code examples
javaandroidnotificationsr.java-file

Android Notification Without R.java


I need to show local notification in Android. But Notification builder object should need any icon to show it in the status bar. It has a certain mandatory function like setSmallIcon(int). It takes integer argument from R.java file. But I need to give direct image URL without using R.java file. Code:

 NotificationCompat.Builder builder = new Builder(getContext());        
            Notification notification = builder.setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle(title)
                    .setContentText(text)
                    .build();

Without R.drawable.ic_launcher. How can I achieve this?


Solution

  • First of all, you should download your image: https://github.com/koush/ion

    Then:

    Icon ic = Icon.createWithContentUri("uri of your downloaded image");  
    builder.setSmallIcon(ic);