使用cordova推送插件推送带有大图片的通知 [英] Push notifications with big Images using cordova push plugin

查看:116
本文介绍了使用cordova推送插件推送带有大图片的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得类似flipkart或myntra这样的推送通知。 (推式通知将附带一张大图,详细介绍商品,点击商品将进入商品区域)。有谁知道如何完成它。
我有类似这样的代码:

I want to get push notification something like flipkart or myntra does. (Push notification will come with an Big image detailing about offers, on clicking of which will take to offers zone). Does anyone know how to get it done. I have code something like this:

NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(context)
            .setDefaults(defaults)
            .setStyle(new NotificationCompat.BigTextStyle().bigText("This is a test for push notification with big images."))
            .setLargeIcon(icon)
            .setSmallIcon(context.getApplicationInfo().icon)
            .setWhen(System.currentTimeMillis())
            .setContentTitle(extras.getString("title"))
            .setTicker(extras.getString("title"))
            .setContentIntent(contentIntent)
            .setAutoCancel(true);


推荐答案

有时,我创建了拉动请求

重要代码:

public void createBigPicNotification(Context context, Bundle extras)
{
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    String appName = getAppName(this);

    .
    .
    .


    String bigPictureUrl= null;
    bigPictureUrl=extras.getString("bigPicture");
    Bitmap bigPictureBMP = null;
    if (bigPictureUrl != null) {
        try {
        URL url = new URL(bigPictureUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.connect();
        InputStream input = connection.getInputStream();
            bigPictureBMP = BitmapFactory.decodeStream(input);
        } catch (IOException e) {
        e.printStackTrace();
        }
    }

    NotificationCompat.BigPictureStyle bigPicStyle = new
        NotificationCompat.BigPictureStyle();
    bigPicStyle.setBigContentTitle(extras.getString("title"));
    bigPicStyle.setSummaryText(extras.getString("message"));
    bigPicStyle.bigPicture(bigPictureBMP);

    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(context)
            .setDefaults(defaults)
            .setSmallIcon(context.getApplicationInfo().icon)
            .setWhen(System.currentTimeMillis())
            .setTicker(extras.getString("title"))
                    .setContentIntent(contentIntent)
                    .setAutoCancel(true)
                    .setStyle(bigPicStyle);

    String message = extras.getString("message");
    if (message != null) {
        mBuilder.setContentText(message);
    } else {
        mBuilder.setContentText("<missing message content>");
    }

    String msgcnt = extras.getString("msgcnt");
    if (msgcnt != null) {
        mBuilder.setNumber(Integer.parseInt(msgcnt));
    }

    int notId = 0;

    try {
        notId = Integer.parseInt(extras.getString("notId"));
    }
    catch(NumberFormatException e) {
        Log.e(TAG, "Number format exception - Error parsing Notification ID: " + e.getMessage());
    }
    catch(Exception e) {
        Log.e(TAG, "Number format exception - Error parsing Notification ID" + e.getMessage());
    }

    mNotificationManager.notify((String) appName, notId, mBuilder.build());
}

这篇关于使用cordova推送插件推送带有大图片的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆