我致电时使用YouTube API:
new DownloadImageTask(activity,i,notificationDetails).execute(notificationDetails.get(i).getThumbUri())
这个班级:
public class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
private int currentIndex;
private LoginActivity activity;
private ArrayList<VideoData> notifyDetails;
private String urlDisplay;
public DownloadImageTask(LoginActivity activity, int notificationDetailsIndex, ArrayList<VideoData> notificationDetails){
currentIndex = notificationDetailsIndex;
this.activity = activity;
this.notifyDetails = notificationDetails;
}
@Override
protected Bitmap doInBackground(String... urls){
urlDisplay = urls[0];
Bitmap image = null;
InputStream in = null;
try{
in = new java.net.URL(urlDisplay).openStream();
image = BitmapFactory.decodeStream(in);
} catch(Exception e){
Log.e("Error decoding bitmap", Log.getStackTraceString(e));
}finally{
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return image;
}
@Override
protected void onPostExecute(Bitmap image){
Log.d("bitmap value", String.valueOf(image))
VideoData video = notifyDetails.get(currentIndex);
activity.notificationBuilder(video.getTitle(), video.getVideoChannelTitle(), image);
}
}
}
onPostExecute()中的Log.d()方法返回如下内容:
D/bitmap value﹕ android.graphics.Bitmap@41180d60
我想设置一个带有大图标的通知,但它不起作用.
以下是Activity类中的通知方法:
public void notificationBuilder(String videoTitle, String channelTitle, Bitmap largeBitmap){
NotificationCompat.Builder mBuilder;
Log.d("Bitmapdrawable set", ""+ String.valueOf(largeBitmap));
mBuilder = new NotificationCompat.Builder(this)
.setLargeIcon(largeBitmap)
.setContentTitle(channelTitle + " uploaded a video")
.setContentText(videoTitle);
Intent resultIntent = new Intent(this, LoginActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(LoginActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(
0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(
Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
我在logcat中得到的错误显示“忽略带有icon == 0的通知”,即使notifyBuilder()方法的第三行:(Log.d(“Bitmapdrawable set”,“”String.valueOf(largeBitmap)) ;返回:D / Bitmapdrawable集:logcat中的android.graphics.Bitmap@41433b80.
2191-2191/system_process E/NotificationService﹕ Ignoring notification with icon==0: Notification(pri=0 contentView=com.myapp/0x109008f vibrate=null sound=null defaults=0x0 flags=0x0 kind=[null])
解决方法:
你也需要调用setSmallIcon().