android - 位图作为通知图标

标签 android

我是android新手,我有以下代码:

  URL url = new URL(userpic);
  URLConnection conn = url.openConnection();
  HttpURLConnection httpConn = (HttpURLConnection)conn;
  httpConn.setRequestMethod("GET");
  httpConn.connect();
  if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
        InputStream inputStream = httpConn.getInputStream();
        Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
        inputStream.close();

        // make a Drawable from Bitmap to allow to set the BitMap
        gdrawable = new BitmapDrawable(bitmap);
        myNotification = new Notification(gdrawable, "Notification!", System.currentTimeMillis());

对于这些代码 "Notification(gdrawable, "Notification!",System.currentTimeMillis());"会出错,它需要我获取 int id。 如何获得 gdrawable ID?

最佳答案

可以将图片文件放在res->drawable(或drawable-hdpi,ldpi,mdpi)中,例如notify.png 并使用它 myNotification = new Notification(R.id.notify, “通知!”,System.currentTimeMillis());

关于android - 位图作为通知图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6108996/

相关文章:

android - 使用 Sonarqube 分析 Android Studio (Gradle) 项目

android - 静态单例未在 Activity 中初始化。有什么问题吗?

java - 同步两部手机的系统时间

android - 如何在信息窗口中显示相应标记的适当的多个数据

java - 云端点方法可见性

android - android 中不显示进度对话框?

android - 以编程方式更改主启动器 Activity

android - 如何在android中使用磁力计查找磁场强度

java - 改造和 SimpleXmlConverterFactory

java - 在对话框 fragment 中打开 AlertDialog