2011-05-24 52 views
1

我的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?

+0

有沒有人知道如何使用位圖作爲通知圖標?我真的需要它。我想使用外部圖像作爲通知圖標。 – dong221 2011-06-25 10:55:31

回答

1

你可以把圖像文件中水庫>繪製(或繪製,華電國際,LDPI,MDPI),例如notify.png ,並用它 myNotification =新的通知(R.id.notify, 「通知! 「,System.currentTimeMillis());

+0

感謝Konstantin,但我更願意在不同用戶的URL上加載圖像。我找到解決方案,似乎不可能使用URL圖像作爲通知圖標。[link](http://stackoverflow.com/questions/2059933/setting-an-android-notification-icon-to-a-remote -url) – user767528 2011-05-24 11:10:12