我想做一个有大图片的通知。我已经搜索并找到了一些代码,并进行了自定义,但它没有显示大图像。这是我的代码;
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);
}
}当活动运行时。它会显示通知,但不会显示图像。
我做错了什么?
谢谢
发布于 2016-02-01 01:16:14
可能是图像太大,或者您没有展开图像(通过向下拉它)。
您还可以设置通知的优先级。这可能会自动展开您的通知图像。
.setPriority(Notification.PRIORITY_MAX)发布于 2021-11-20 03:35:39
在通知活动中设置通知的优先级。并且还可以保持图像的小尺寸。
.setPriority(Notification.PRIORITY_MAX)
https://stackoverflow.com/questions/31878620
复制相似问题