我的通知中没有显示大样式的图片

时间:2015-09-26 02:28:42

标签: android

我正在为android中的通知实现一个大图片视图。我首先使用异步任务类下载imagefile,然后将下载的图像推送到我的通知方法。图片可以从我的服务器下载(因为它显示了.setLargeIcon中下载的图片),但它无法以大样式格式显示。

以下是我的所作所为

   private class Notification extends AsyncTask<String, Void, Bitmap> {

Context c;
String message;

public Notification(Context context) {
    super();
    this.c = context;
}

@Override
protected Bitmap doInBackground(String... params) {

    InputStream in;
    String urls="http//myimagefile";
    try {

URL url = new URL(urls);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
in = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(in);
return myBitmap;




    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

@Override
protected void onPostExecute(Bitmap result) {

    super.onPostExecute(result);
    try {
        NotificationManager notificationManager = (NotificationManager) c
                .getSystemService(Context.NOTIFICATION_SERVICE);

        Intent intent = new Intent(c, News.class);
        intent.putExtra("alliswell", false);


        Notification notification = new NotificationCompat.Builder(c)
        .setContentTitle("title")
        .setContentText("message")
        .setSmallIcon(R.drawable.ic_launcher)
        .setLargeIcon(result) // The downloaded bitmap is able to show here
        .setStyle(new NotificationCompat.BigPictureStyle()
            .bigPicture(result)) // However it is unable to show in this format
    .build();


        // hide the notification after its selected
        notification.flags |= Notification.FLAG_AUTO_CANCEL;

        notificationManager.notify(1, notification);

    } catch (Exception e) {
        e.printStackTrace();
    }
}
}

更新

我甚至认为我的图像尺寸可能不会在我的通知框中显示。  然而,我尝试了.setStyle(new Notification.BigTextStyle().bigText(aVeryLongString)),但也没有用。我想我可能做错了什么。我希望有人帮助我,因为我已经从这个来源(http://developer.android.com/reference/android/support/v4/app/NotificationCompat.BigTextStyle.html)正确实现了所有功能,但似乎都没有。

请问我在上面的代码中做错了什么,我很感激知道,非常感谢。

0 个答案:

没有答案