【发布时间】:2015-08-07 13:11:08
【问题描述】:
我想制作一个包含大图像的通知。我已经搜索并找到了一些代码并进行了自定义,但它没有显示大图像。这是我的代码;
private class sendNotification extends AsyncTask<String, Void, Bitmap> {
Bitmap remote_picture = null;
Context ctx;
String message;
@Override
protected Bitmap doInBackground(String... params) {
InputStream in;
message = "msg";
try {
URL url = new URL("http://website.com/img.png");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
in = connection.getInputStream();
remote_picture = BitmapFactory.decodeStream(in);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Bitmap result) {
super.onPostExecute(result);
// Create the style object with BigPictureStyle subclass.
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
NotificationCompat.BigPictureStyle notiStyle = new NotificationCompat.BigPictureStyle();
notiStyle.setBigContentTitle("Big Picture Expanded");
notiStyle.setSummaryText("Nice big picture.");
// Add the big picture to the style.
notiStyle.bigPicture(remote_picture);
// Creates an explicit intent for an ResultActivity to receive.
Intent resultIntent = new Intent(FistActiivty.this, FistActiivty.class);
// This ensures that the back button follows the recommended
// convention for the back key.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(FistActiivty.this);
// Adds the back stack for the Intent (but not the Intent itself).
stackBuilder.addParentStack(FistActiivty.class);
// Adds the Intent that starts the Activity to the top of the stack.
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
Notification myNotification = new NotificationCompat.Builder(FistActiivty.this)
.setSmallIcon(R.drawable.ic_launcher).setAutoCancel(false).setLargeIcon(remote_picture)
.setContentIntent(resultPendingIntent).setContentTitle("Big Picture Normal")
.setContentText("This is an example of a Big Picture Style.").setStyle(notiStyle).build();
notificationManager.notify(1, myNotification);
}
}
当活动运行时。它显示通知,但不显示图像。
我做错了什么?
谢谢
【问题讨论】:
-
曾经遇到过类似的问题,发现需要小图,否则通知可能会出现异常。所以也尝试添加一个小图像。
标签: android android-notifications