Working with the YouTube API, when I call:
new DownloadImageTask(activity, i, notificationDetails).execute(notificationDetails.get(i).getThumbUri())
for this class:
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);
}
}
}
The Log.d() method in onPostExecute() returns something like:
D/bitmap value﹕ android.graphics.Bitmap@41180d60
I want to set a notification with a large icon, but it is not working. Here is the notification method in Activity class:
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());
}
The error below that I get in logcat shows "ignoring notification with icon==0", even though the third line of the notificationBuilder() method: (Log.d("Bitmapdrawable set", ""+ String.valueOf(largeBitmap));
returns: D/Bitmapdrawable set﹕ android.graphics.Bitmap@41433b80
in logcat.
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])
You need to call setSmallIcon()
too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With