【问题标题】:android -Expandable Notifications not showing big imagesandroid - 可扩展通知不显示大图像
【发布时间】: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


【解决方案1】:

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

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

.setPriority(Notification.PRIORITY_MAX)

【讨论】:

  • 这是正确答案。根本原因是这些通知仅在它们是一个人的通知抽屉顶部的通知时才会展开。 Jaspinder 的答案有效,因为您基本上是在强制通知位于顶部。它可靠吗?不,因为您正在与其他应用竞争手机上的头把交椅,但它已经做到了。
【解决方案2】:

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

.setPriority(Notification.PRIORITY_MAX)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-09
    • 2014-09-17
    • 2018-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多