【问题标题】:Push notifications with big Images using cordova push plugin使用 Cordova 推送插件推送带有大图像的通知
【发布时间】:2015-02-25 12:18:10
【问题描述】:

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

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);

【问题讨论】:

    标签: android push-notification cordova-plugins


    【解决方案1】:

    以前,我为此创建了一个pull request

    重要代码:

    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());
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-17
      • 2017-12-02
      • 1970-01-01
      • 2017-02-02
      • 1970-01-01
      相关资源
      最近更新 更多