没有 R.java 的 Android 通知 [英] Android Notification Without R.java

查看:124
本文介绍了没有 R.java 的 Android 通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 Android 中显示本地通知.但是通知构建器对象应该需要任何图标才能在状态栏中显示它.它有一定的强制功能,如setSmallIcon(int).它从 R.java 文件中获取整数参数.但是我需要在不使用 R.java 文件的情况下提供直接图像 URL.代码:

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();

没有 R.drawable.ic_launcher.我怎样才能做到这一点?

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

推荐答案

首先,您应该下载您的图像:https://github.com/koush/ion

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

那么:

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

这篇关于没有 R.java 的 Android 通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆