首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安卓-Expandable通知不显示大图像

安卓-Expandable通知不显示大图像
EN

Stack Overflow用户
提问于 2015-08-07 21:11:08
回答 2查看 1.5K关注 0票数 1

我想做一个有大图片的通知。我已经搜索并找到了一些代码,并进行了自定义,但它没有显示大图像。这是我的代码;

代码语言:javascript
复制
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);
    }
}

当活动运行时。它会显示通知,但不会显示图像。

我做错了什么?

谢谢

EN

回答 2

Stack Overflow用户

发布于 2016-02-01 01:16:14

可能是图像太大,或者您没有展开图像(通过向下拉它)。

您还可以设置通知的优先级。这可能会自动展开您的通知图像。

代码语言:javascript
复制
.setPriority(Notification.PRIORITY_MAX)
票数 3
EN

Stack Overflow用户

发布于 2021-11-20 03:35:39

在通知活动中设置通知的优先级。并且还可以保持图像的小尺寸。

.setPriority(Notification.PRIORITY_MAX)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31878620

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档