Android Firebase推送通知-如何在通知中显示多行消息

Android Firebase推送通知-如何在通知中显示多行消息,android,firebase,push-notification,firebase-cloud-messaging,Android,Firebase,Push Notification,Firebase Cloud Messaging,仅在一行中获取推送通知的消息,而我希望它在多行中使用BigPictureStyle和Base(两种通知样式) 请参见所附的屏幕截图,而在这张图中,我们只是显示了“来自Firebase云的Hello Messaging”,因此这只适合一行 但事实是,如果我试图显示“来自Firebase云消息的Hello,以及来自Firebase云消息的Hello”,即使这样,我也只能在单行中收到消息,末尾有三个点,如下图所示 以下是代码中所需的部分,我正在使用: NotificationCompat.Build

仅在一行中获取推送通知的
消息
,而我希望它在
多行中
使用
BigPictureStyle
和Base(两种通知样式)

请参见所附的屏幕截图,而在这张图中,我们只是显示了
“来自Firebase云的Hello Messaging”
,因此这只适合一行

但事实是,如果我试图显示“来自Firebase云消息的Hello,以及来自Firebase云消息的Hello”,即使这样,我也只能在
单行中收到消息,末尾有三个点,如下图所示

以下是代码中所需的
部分,我正在使用:

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setLargeIcon(image)/*Notification icon image*/
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle(messageTitle)
                .setContentText(messageBody)
                .setStyle(new NotificationCompat.BigPictureStyle()
                        .bigPicture(image)
                        .setBigContentTitle(messageTitle)
                        .setSummaryText(Html.fromHtml(messageBody)
                        .toString()))/*Notification with Image*/
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);
注意:同样的问题,无论何时,我都会面临,我发送的消息没有大图(基本/简单推送通知)

请参见此屏幕截图:


因此,唯一需要考虑的是如何在通知中显示多行消息?

您几乎已经拥有了它,只需设置属性即可

    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setAutoCancel(true);

    NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
    bigTextStyle.setBigContentTitle("Title");
    bigTextStyle.bigText("Lorem ipsum dolor sit amet, consectetur adipiscing elit," +
            " sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " +
            "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris " +
            "nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in.");

    notificationBuilder.setStyle(bigTextStyle);

    NotificationManager mNotifyMgr = (NotificationManager)
            getSystemService(NOTIFICATION_SERVICE);
    mNotifyMgr.notify(1, notificationBuilder.build());

您可以使用@Dus answer显示多行……但使用
bigPictureSyle
时,它在setSummaryText方法中始终只有一行,其他选项是创建
RemoteView
,并根据您所需的设计实现UI


有关
远程视图
参考

您应该使用自己的布局:

Builder builder = new Builder(context);
builder.setSmallIcon(R.drawable.star_white)
builder.setAutoCancel(true)
builder.setContentIntent(pendingIntent);
builder.setPriority(NotificationCompat.PRIORITY_MAX);

RemoteViews remoteViewsBig = new RemoteViews(context.getPackageName(), R.layout.notification_big);
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.notification_small);
remoteViewsBig.setImageViewBitmap(R.id.banner, bitmap);

remoteViewsBig.setTextViewText(R.id.button, data.getButtonText());
remoteViews.setTextViewText(R.id.button, data.getButtonText());

remoteViewsBig.setTextViewText(R.id.text_title, data.getTitle());
remoteViews.setTextViewText(R.id.text_title, data.getTitle());

remoteViewsBig.setTextViewText(R.id.text_content, data.getContent());
remoteViews.setTextViewText(R.id.text_content, data.getContent());

builder.setCustomContentView(remoteViews);
builder.setCustomBigContentView(remoteViewsBig);

NotificationManager notificationManager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notificationId, builder.build());
和xml文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:background="@color/custom_blue_gray_800"
              android:orientation="horizontal"
    >

    <ImageView
        android:layout_width="44dp"
        android:layout_height="44dp"
        android:layout_gravity="center"
        android:src="@mipmap/ic_launcher"
        />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="12dp"
        android:layout_marginRight="12dp"
        android:layout_weight="1"
        android:gravity="center_vertical"
        android:orientation="vertical"
        android:padding="8dp"
        >

        <TextView
            android:id="@+id/text_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@android:color/white"
            android:textSize="16sp"
            tools:text="Title"
            />

        <TextView
            android:id="@+id/text_content"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@android:color/darker_gray"
            android:textSize="14sp"
            tools:text="text\ntext\ntext"
            />

    </LinearLayout >

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="36dp"
        android:layout_gravity="center_vertical"
        android:background="@drawable/button_main"
        android:text="Click"
        android:textColor="@android:color/white"
        android:textSize="12sp"
        />

</LinearLayout >


试试这个:-

NotificationCompat.Builder builder = new NotificationCompat.Builder(
        context);
Notification notification = builder.setContentIntent(contentIntent)
        .setSmallIcon(icon).setTicker(appname).setWhen(0)
        .setAutoCancel(true).setContentTitle(appname)
        .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
        .setContentText(message).build();

notificationManager.notify(0, notification);

我希望你已经习惯了。 选中此项:

   NotificationCompat.Builder builder = new NotificationCompat.Builder(
            context);
    Notification notification = builder.setContentIntent(contentIntent)
            .setSmallIcon(icon).setTicker(appname).setWhen(0)
            .setAutoCancel(true).setContentTitle(appname)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
            .setContentText(message).build();

    notificationManager.notify(0, notification);
请参阅此链接:


谢谢…

这就是我如何在通知中显示大图像和一些多行文字的方法。这是我项目中的工作代码

fcm中有两种fcm消息<代码>显示消息
数据消息
。我使用
数据消息
在前台和后台处理fcm通知

  /**
 * Created by Mohammed Farhan on 01-08-2017.
 */

public class MyFirebaseMessagingService extends FirebaseMessagingService
{

    private static final String TAG = "MyFirebaseMsgService";
    private AppAuth auth;

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage)
    {
    }




        /*To check if remoteMessage is empty, if not empty then read the id from "title" field*/
        if (remoteMessage.getData().size() > 0)
        {
            Map<String, String> data = remoteMessage.getData();
            String title = data.get("title");
            sendNotification(title);
            Log.d(TAG, title.toString());
        }

    }


    private void sendNotification(String title)
    {


        final String id = title;

        /* Here DataFromServer is custom method, used to sync data from my server. It has interface method to listen it when data sync and adding it to local sql completes*/
        DataFromServer dataFromServer = new DataFromServer(this);
        dataFromServer.setDataLoadCompleteListener(new DataLoadCompleteListener()
        {
            @Override
            public void dataLoadComplete()
            {

            /*AppNotificationDAO is a class which  has many DAO(Data Access Object) method. I have used DAO to make ease in saving,querying data from local sql*/
                AppNotificationDAO appNotificationDAO = new AppNotificationDAO(MyFirebaseMessagingService.this);

                /*getAppNotificationByID is DAO method which does server communication and fetch data from it based on Id(Here its notificationId)*/
                AppNotification appNotification = appNotificationDAO.getAppNotificationByID(Long.valueOf(id));
                if (appNotification != null)
                {
                    if (appNotification.getPhoto().equalsIgnoreCase("NA"))
                    {
                    /* photo is a field in my AppNotification class and getPhoto() is getter  and appNotification.getPhoto() returns the value stored in it. Here am using it to save url of image related to notification in my web app*/

                        /*if url is not present then below method displays just a text as notification*/
                        showBigTextStyleNotification(appNotification);
                    }
                    else
                    {


                    /*if there is url then am running asyncTask to get bitmap of that image and show it in notification tray along with text. Below method does that*/
                        new showBigPictureStyleNotification(MyFirebaseMessagingService.this,
                                appNotification.getMessage(),
                                Links.NOTIFICATION_IMAGE + "/" + appNotification.getPhoto(), appNotification)
                                .execute();

                                /* am passing some variables inside above methods, and Links is a class where have defined some strings (links) to my webapp*/
                    }
                }
            }
        });
        dataFromServer.getAppNotificationFromServer(Long.valueOf(id));




    }

    private void displayNotification(AppNotification appNotification)
    {
        Intent intent = new Intent(MyFirebaseMessagingService.this, NotificationListActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(MyFirebaseMessagingService.this,
                0, intent, PendingIntent.FLAG_ONE_SHOT);

        Uri notificationSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setContentTitle("KSP_PQRS");
        builder.setContentText(appNotification.getSubject());
        builder.setContentIntent(pendingIntent);
        builder.setSmallIcon(R.drawable.notification);
        builder.setSound(notificationSoundUri);
        builder.build();

        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(100, builder.build());
    }

    private void showBigTextStyleNotification(AppNotification appNotification)
    {
        Bitmap icon1 = BitmapFactory.decodeResource(getResources(),
                R.drawable.police_logo);

        android.support.v4.app.NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                this).setAutoCancel(true)
                .setContentTitle(appNotification.getSubject())
                .setSmallIcon(R.drawable.police_logo)
                .setLargeIcon(icon1)
                .setContentText(appNotification.getMessage());

        NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
        bigText.bigText(appNotification.getMessage());
        bigText.setBigContentTitle(appNotification.getSubject());
        bigText.setSummaryText(getResources().getString(R.string.app_name));
        mBuilder.setStyle(bigText);
        mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        mBuilder.setPriority(NotificationCompat.PRIORITY_MAX);

        // Creates an explicit intent for an Activity in your app
        Intent resultIntent;
        if (appNotification.getType().equalsIgnoreCase("GEN"))
        {
            resultIntent = new Intent(this, NotificationListActivity.class);
        }
        else
        {
            resultIntent = new Intent(this, MainActivity.class);
        }

        TaskStackBuilder stackBuilder = TaskStackBuilder
                .create(this);
        stackBuilder.addParentStack(MainActivity.class);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder
                .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(resultPendingIntent);

        NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(((int) appNotification.getId()) + 1000, mBuilder.build());
    }

    private class showBigPictureStyleNotification extends AsyncTask<String, Void, Bitmap>
    {
        private Context mContext;
        private String title, message, imageUrl;
        AppNotification appNotification;

        showBigPictureStyleNotification(Context context, String message, String imageUrl, AppNotification appNotification)
        {
            super();
            this.mContext = context;
            this.title = getResources().getString(R.string.app_name);
            this.message = message;
            this.imageUrl = imageUrl;
            this.appNotification = appNotification;
        }

        @Override
        protected Bitmap doInBackground(String... params)
        {
            InputStream in;
            try
            {
                auth = new AppAuthDAO(mContext).getAppAuth();
                byte[] toEncrypt = (auth.getUsername() + ":" + auth.getPassword() + ":" + auth.getDeviceId()).getBytes();
                String encryptedCredentials = Base64.encodeToString(toEncrypt, Base64.NO_WRAP);

                URL url = new URL(this.imageUrl);
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                connection.setDoInput(true);
                connection.setRequestProperty("Authorization", "Basic " + encryptedCredentials);
                connection.connect();
                in = connection.getInputStream();
                Bitmap myBitmap = BitmapFactory.decodeStream(in);
                return myBitmap;
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return null;
        }

        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @Override
        protected void onPostExecute(Bitmap result)
        {
            super.onPostExecute(result);

            Intent intent;
            if (appNotification.getType().equalsIgnoreCase("GEN"))
            {
                intent = new Intent(mContext, NotificationListActivity.class);
            }

            else
            {
                intent = new Intent(mContext, MainActivity.class);
            }

            PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 100, intent, PendingIntent.FLAG_ONE_SHOT);

            NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
            Notification notif = new Notification.Builder(mContext)
                    .setContentIntent(pendingIntent)
                    .setContentTitle(title)
                    .setContentText(appNotification.getSubject())
                    .setTicker(message)
                    .setSubText(message)
                    .setSmallIcon(R.drawable.police_logo)
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.police_logo))

                    /*using setStyle am setting big image along with some lines of text in notifications*/
                    .setStyle(new Notification.BigPictureStyle().bigPicture(result))
                    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                    .build();
            notif.flags |= Notification.FLAG_AUTO_CANCEL;
            notificationManager.notify(((int) appNotification.getId()) + 1000, notif);
        }
    }
}
/**
*由Mohammed Farhan于2017年8月1日创作。
*/
公共类MyFirebaseMessagingService扩展了FirebaseMessagingService
{
私有静态最终字符串TAG=“MyFirebaseMsgService”;
私人AppAuth;
@凌驾
收到消息时公共无效(RemoteMessage RemoteMessage)
{
}
/*要检查remoteMessage是否为空,如果不为空,则从“标题”字段读取id*/
如果(remoteMessage.getData().size()>0)
{
Map data=remoteMessage.getData();
字符串title=data.get(“title”);
发送通知(标题);
Log.d(标记,title.toString());
}
}
私有无效发送通知(字符串标题)
{
最终字符串id=标题;
/*这里DataFromServer是自定义方法,用于从我的服务器同步数据。它有接口方法在数据同步并将其添加到本地sql完成时侦听数据*/
DataFromServer DataFromServer=新的DataFromServer(此);
dataFromServer.setDataLoadCompleteListener(新DataLoadCompleteListener()
{
@凌驾
public void dataLoadComplete()
{
/*AppNotificationDAO是一个具有许多DAO(数据访问对象)方法的类。我使用DAO简化了从本地sql保存、查询数据的过程*/
AppNotificationDAO AppNotificationDAO=新的AppNotificationDAO(MyFirebaseMessagingService.this);
/*getAppNotificationByID是一种DAO方法,它执行服务器通信并根据Id(此处为其notificationId)从中获取数据*/
AppNotification AppNotification=appNotificationDAO.getAppNotificationByID(Long.valueOf(id));
if(appNotification!=null)
{
if(appNotification.getPhoto().equalsIgnoreCase(“NA”))
{
/*photo是我的AppNotification类中的一个字段,getPhoto()是getter,AppNotification.getPhoto()返回存储在其中的值。我在这里使用它在我的web应用中保存与通知相关的图像的url*/
/*若url不存在,那个么下面的方法只显示一个文本作为通知*/
showBigTextStyleNotification(appNotification);
}
其他的
{
/*若有url,那个么我将运行asyncTask来获取该图像的位图,并将其和文本一起显示在通知栏中*/
新showBigPictureStyleNotification(MyFirebaseMessagingService.this,
appNotification.getMessage(),
Links.NOTIFICATION_IMAGE+“/”+appNotification.getPhoto(),appNotification)
.execute();
/*我在上面的方法中传递了一些变量,而Links是一个类,其中定义了一些字符串(Links)到我的webapp*/
}
}
}
});
dataFromServer.getAppNotificationFromServer(Long.valueOf(id));
}
私有void显示通知(AppNotification AppNotification)
{
意向意向=新意向(MyFirebaseMessagingService.this,NotificationListActivity.class);
intent.addFlags(intent.FLAG\u ACTIVITY\u CLEAR\u TOP);
PendingEvent PendingEvent=PendingEvent.getActivity(MyFirebaseMessagingService.this,
0,意图,悬而未决。标志(一次);
Uri notificationSoundUri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_通知);
NotificationCompat.Builder=新建NotificationCompat.Builder(此);
建造商:setContentTitle(“KSP_PQRS”);
setContentText(appNotification.getSubject());
builder.setContentIntent(挂起内容);
builder.setSmallIcon(R.drawable.notification);
builder.setSound(notificationSoundUri);
builder.build();
NotificationManager NotificationManager=(Notificati
  /**
 * Created by Mohammed Farhan on 01-08-2017.
 */

public class MyFirebaseMessagingService extends FirebaseMessagingService
{

    private static final String TAG = "MyFirebaseMsgService";
    private AppAuth auth;

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage)
    {
    }




        /*To check if remoteMessage is empty, if not empty then read the id from "title" field*/
        if (remoteMessage.getData().size() > 0)
        {
            Map<String, String> data = remoteMessage.getData();
            String title = data.get("title");
            sendNotification(title);
            Log.d(TAG, title.toString());
        }

    }


    private void sendNotification(String title)
    {


        final String id = title;

        /* Here DataFromServer is custom method, used to sync data from my server. It has interface method to listen it when data sync and adding it to local sql completes*/
        DataFromServer dataFromServer = new DataFromServer(this);
        dataFromServer.setDataLoadCompleteListener(new DataLoadCompleteListener()
        {
            @Override
            public void dataLoadComplete()
            {

            /*AppNotificationDAO is a class which  has many DAO(Data Access Object) method. I have used DAO to make ease in saving,querying data from local sql*/
                AppNotificationDAO appNotificationDAO = new AppNotificationDAO(MyFirebaseMessagingService.this);

                /*getAppNotificationByID is DAO method which does server communication and fetch data from it based on Id(Here its notificationId)*/
                AppNotification appNotification = appNotificationDAO.getAppNotificationByID(Long.valueOf(id));
                if (appNotification != null)
                {
                    if (appNotification.getPhoto().equalsIgnoreCase("NA"))
                    {
                    /* photo is a field in my AppNotification class and getPhoto() is getter  and appNotification.getPhoto() returns the value stored in it. Here am using it to save url of image related to notification in my web app*/

                        /*if url is not present then below method displays just a text as notification*/
                        showBigTextStyleNotification(appNotification);
                    }
                    else
                    {


                    /*if there is url then am running asyncTask to get bitmap of that image and show it in notification tray along with text. Below method does that*/
                        new showBigPictureStyleNotification(MyFirebaseMessagingService.this,
                                appNotification.getMessage(),
                                Links.NOTIFICATION_IMAGE + "/" + appNotification.getPhoto(), appNotification)
                                .execute();

                                /* am passing some variables inside above methods, and Links is a class where have defined some strings (links) to my webapp*/
                    }
                }
            }
        });
        dataFromServer.getAppNotificationFromServer(Long.valueOf(id));




    }

    private void displayNotification(AppNotification appNotification)
    {
        Intent intent = new Intent(MyFirebaseMessagingService.this, NotificationListActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(MyFirebaseMessagingService.this,
                0, intent, PendingIntent.FLAG_ONE_SHOT);

        Uri notificationSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setContentTitle("KSP_PQRS");
        builder.setContentText(appNotification.getSubject());
        builder.setContentIntent(pendingIntent);
        builder.setSmallIcon(R.drawable.notification);
        builder.setSound(notificationSoundUri);
        builder.build();

        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(100, builder.build());
    }

    private void showBigTextStyleNotification(AppNotification appNotification)
    {
        Bitmap icon1 = BitmapFactory.decodeResource(getResources(),
                R.drawable.police_logo);

        android.support.v4.app.NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                this).setAutoCancel(true)
                .setContentTitle(appNotification.getSubject())
                .setSmallIcon(R.drawable.police_logo)
                .setLargeIcon(icon1)
                .setContentText(appNotification.getMessage());

        NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
        bigText.bigText(appNotification.getMessage());
        bigText.setBigContentTitle(appNotification.getSubject());
        bigText.setSummaryText(getResources().getString(R.string.app_name));
        mBuilder.setStyle(bigText);
        mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        mBuilder.setPriority(NotificationCompat.PRIORITY_MAX);

        // Creates an explicit intent for an Activity in your app
        Intent resultIntent;
        if (appNotification.getType().equalsIgnoreCase("GEN"))
        {
            resultIntent = new Intent(this, NotificationListActivity.class);
        }
        else
        {
            resultIntent = new Intent(this, MainActivity.class);
        }

        TaskStackBuilder stackBuilder = TaskStackBuilder
                .create(this);
        stackBuilder.addParentStack(MainActivity.class);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder
                .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(resultPendingIntent);

        NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(((int) appNotification.getId()) + 1000, mBuilder.build());
    }

    private class showBigPictureStyleNotification extends AsyncTask<String, Void, Bitmap>
    {
        private Context mContext;
        private String title, message, imageUrl;
        AppNotification appNotification;

        showBigPictureStyleNotification(Context context, String message, String imageUrl, AppNotification appNotification)
        {
            super();
            this.mContext = context;
            this.title = getResources().getString(R.string.app_name);
            this.message = message;
            this.imageUrl = imageUrl;
            this.appNotification = appNotification;
        }

        @Override
        protected Bitmap doInBackground(String... params)
        {
            InputStream in;
            try
            {
                auth = new AppAuthDAO(mContext).getAppAuth();
                byte[] toEncrypt = (auth.getUsername() + ":" + auth.getPassword() + ":" + auth.getDeviceId()).getBytes();
                String encryptedCredentials = Base64.encodeToString(toEncrypt, Base64.NO_WRAP);

                URL url = new URL(this.imageUrl);
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                connection.setDoInput(true);
                connection.setRequestProperty("Authorization", "Basic " + encryptedCredentials);
                connection.connect();
                in = connection.getInputStream();
                Bitmap myBitmap = BitmapFactory.decodeStream(in);
                return myBitmap;
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return null;
        }

        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @Override
        protected void onPostExecute(Bitmap result)
        {
            super.onPostExecute(result);

            Intent intent;
            if (appNotification.getType().equalsIgnoreCase("GEN"))
            {
                intent = new Intent(mContext, NotificationListActivity.class);
            }

            else
            {
                intent = new Intent(mContext, MainActivity.class);
            }

            PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 100, intent, PendingIntent.FLAG_ONE_SHOT);

            NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
            Notification notif = new Notification.Builder(mContext)
                    .setContentIntent(pendingIntent)
                    .setContentTitle(title)
                    .setContentText(appNotification.getSubject())
                    .setTicker(message)
                    .setSubText(message)
                    .setSmallIcon(R.drawable.police_logo)
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.police_logo))

                    /*using setStyle am setting big image along with some lines of text in notifications*/
                    .setStyle(new Notification.BigPictureStyle().bigPicture(result))
                    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                    .build();
            notif.flags |= Notification.FLAG_AUTO_CANCEL;
            notificationManager.notify(((int) appNotification.getId()) + 1000, notif);
        }
    }
}