diff --git a/iterableapi/src/main/java/com/iterable/iterableapi/IterableConstants.java b/iterableapi/src/main/java/com/iterable/iterableapi/IterableConstants.java index 913b9cca6..96f0cd4c4 100644 --- a/iterableapi/src/main/java/com/iterable/iterableapi/IterableConstants.java +++ b/iterableapi/src/main/java/com/iterable/iterableapi/IterableConstants.java @@ -54,10 +54,11 @@ public final class IterableConstants { public static final String MESSAGING_PLATFORM_AMAZON = "ADM"; public static final String IS_GHOST_PUSH = "isGhostPush"; - public static final String ITERABLE_DATA_KEY = "itbl"; public static final String ITERABLE_DATA_BODY = "body"; - public static final String ITERABLE_DATA_TITLE = "title"; + public static final String ITERABLE_DATA_KEY = "itbl"; + public static final String ITERABLE_DATA_PUSH_IMAGE = "attachment_url"; public static final String ITERABLE_DATA_SOUND = "sound"; + public static final String ITERABLE_DATA_TITLE = "title"; //Device public static final String DEVICE_BRAND = "brand"; diff --git a/iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppManager.java b/iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppManager.java index 6ff5f84fe..dbe5a94a9 100644 --- a/iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppManager.java +++ b/iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppManager.java @@ -156,11 +156,11 @@ static void showFullScreenDialog(Context context, JSONObject dialogParameters, S verticalLayout.addView(imageView); try { Class picassoClass = Class.forName(IterableConstants.PICASSO_CLASS); - if (picassoClass != null) { - + String imageUrl = dialogParameters.optString(IterableConstants.ITERABLE_IN_APP_MAIN_IMAGE); + if (picassoClass != null && !imageUrl.isEmpty()) { Picasso. with(context.getApplicationContext()). - load(dialogParameters.optString(IterableConstants.ITERABLE_IN_APP_MAIN_IMAGE)). + load(imageUrl). resize(dialogWidth, dialogHeight/2). centerInside(). into(imageView); diff --git a/iterableapi/src/main/java/com/iterable/iterableapi/IterableNotification.java b/iterableapi/src/main/java/com/iterable/iterableapi/IterableNotification.java index 31518623c..f7a8d897d 100644 --- a/iterableapi/src/main/java/com/iterable/iterableapi/IterableNotification.java +++ b/iterableapi/src/main/java/com/iterable/iterableapi/IterableNotification.java @@ -9,9 +9,12 @@ import android.content.pm.PackageManager; import android.net.Uri; import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; import android.support.v4.app.NotificationCompat; +import android.widget.RemoteViews; -import java.util.Date; +import com.squareup.picasso.Picasso; /** * @@ -20,6 +23,7 @@ public class IterableNotification extends NotificationCompat.Builder { static final String TAG = "IterableNotification"; private boolean isGhostPush; + private String imageUrl; int requestCode; IterableNotificationData iterableNotificationData; @@ -27,6 +31,37 @@ protected IterableNotification(Context context) { super(context); } + /** + * Combine all of the options that have been set and return a new {@link Notification} + * object. + */ + public Notification build() { + final Notification notification = super.build(); + + final int iconId = android.R.id.icon; + final int bigIconId = mContext.getResources().getIdentifier("android:id/big_picture", null, null); + + Handler handler = new Handler(Looper.getMainLooper()); + handler.post(new Runnable() { + @Override + public void run() { + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN && imageUrl != null) { + final RemoteViews bigContentView = notification.bigContentView; + try { + Class picassoClass = Class.forName(IterableConstants.PICASSO_CLASS); + if (picassoClass != null) { + Picasso.with(mContext).load(imageUrl).into(bigContentView, bigIconId, requestCode, notification); + } + } catch (ClassNotFoundException e) { + IterableLogger.w(TAG, "ClassNotFoundException: Check that picasso is added " + + "to the build dependencies", e); + } + } + } + }); + return notification; + } + /** * Creates and returns an instance of IterableNotification. * @param context @@ -40,6 +75,7 @@ public static IterableNotification createNotification(Context context, Bundle ex String notificationBody = null; String soundName = null; String messageId = null; + String pushImage = null; IterableNotification notificationBuilder = new IterableNotification(context); @@ -47,6 +83,7 @@ public static IterableNotification createNotification(Context context, Bundle ex applicationName = extras.getString(IterableConstants.ITERABLE_DATA_TITLE, applicationName); notificationBody = extras.getString(IterableConstants.ITERABLE_DATA_BODY); soundName = extras.getString(IterableConstants.ITERABLE_DATA_SOUND); + pushImage = extras.getString(IterableConstants.ITERABLE_DATA_PUSH_IMAGE); String iterableData = extras.getString(IterableConstants.ITERABLE_DATA_KEY); notificationBuilder.iterableNotificationData = new IterableNotificationData(iterableData); @@ -66,10 +103,20 @@ public static IterableNotification createNotification(Context context, Bundle ex .setTicker(applicationName).setWhen(0) .setAutoCancel(true) .setContentTitle(applicationName) - .setStyle(new NotificationCompat.BigTextStyle().bigText(notificationBody)) .setPriority(Notification.PRIORITY_HIGH) .setContentText(notificationBody); + if (pushImage != null) { + notificationBuilder.imageUrl = pushImage; + notificationBuilder.setContentText(notificationBody) + .setStyle(new NotificationCompat.BigPictureStyle() + .setBigContentTitle(applicationName) + .setSummaryText(notificationBody) + ); + } else { + notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(notificationBody)); + } + if (soundName != null) { //Removes the file type from the name String[] soundFile = soundName.split("\\."); @@ -142,6 +189,7 @@ private static int getIconId(Context context) { try { ApplicationInfo info = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); iconId = info.metaData.getInt(IterableConstants.NOTIFICATION_ICON_NAME, 0); + IterableLogger.d(TAG, "iconID: "+ info.metaData.get(IterableConstants.NOTIFICATION_ICON_NAME)); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } diff --git a/iterableapi/src/main/java/com/iterable/iterableapi/IterablePushReceiver.java b/iterableapi/src/main/java/com/iterable/iterableapi/IterablePushReceiver.java index 11690627d..d484495a5 100644 --- a/iterableapi/src/main/java/com/iterable/iterableapi/IterablePushReceiver.java +++ b/iterableapi/src/main/java/com/iterable/iterableapi/IterablePushReceiver.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; +import android.os.AsyncTask; import android.os.Bundle; /** @@ -55,16 +56,27 @@ private void handlePushReceived(Context context, Intent intent) { try { mainClass = Class.forName(mainClassName); } catch (ClassNotFoundException e) { - e.printStackTrace(); + IterableLogger.w(TAG, e.toString()); } IterableNotification notificationBuilder = IterableNotification.createNotification( appContext, intent.getExtras(), mainClass); - - IterableNotification.postNotificationOnDevice(appContext, notificationBuilder); + new IterableNotificationBuilder().execute(notificationBuilder); } else { IterableLogger.d(TAG, "Iterable ghost silent push received"); } } } +} + +class IterableNotificationBuilder extends AsyncTask { + + @Override + protected Void doInBackground(IterableNotification... params) { + if ( params != null && params[0] != null) { + IterableNotification notificationBuilder = params[0]; + IterableNotification.postNotificationOnDevice(notificationBuilder.mContext, notificationBuilder); + } + return null; + } } \ No newline at end of file