我是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/