public override void onReceive(Context context, Intent intent)
        {
            /* Once the application identifier is known */
            if ("com.microsoft.azure.engagement.intent.action.APPID_GOT".Equals(intent.Action))
            {
                /* Init the native push agent */
                string appId = intent.getStringExtra("appId");
                EngagementNativePushAgent.getInstance(context).onAppIdGot(appId);

                /*
                 * Request GCM registration identifier, this is asynchronous, the response is made via a
                 * broadcast intent with the <tt>com.google.android.c2dm.intent.REGISTRATION</tt> action.
                 */
                string sender = EngagementUtils.getMetaData(context).getString("engagement:gcm:sender");
                if (sender != null)
                {
                    /* Launch registration process */
                    Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
                    registrationIntent.Package = "com.google.android.gsf";
                    registrationIntent.putExtra("app", PendingIntent.getBroadcast(context, 0, new Intent(), 0));
                    registrationIntent.putExtra("sender", sender.Trim());
                    try
                    {
                        context.startService(registrationIntent);
                    }
                    catch (Exception)
                    {
                        /* Abort if the GCM service can't be accessed. */
                    }
                }
            }
        }
Пример #2
0
        private PendingIntent getPendingIntent()
        {
            Context ctx    = new Context();
            Intent  intent = new Intent(ctx, BroadcastRegister.CreateGeoFenceReceiver(new GeoFenceBroadcast()));

            intent.setAction(ACTION_PROCESS_LOCATION);
            return(PendingIntent.getBroadcast(ctx, ++requestId, intent, PendingIntent.FLAG_UPDATE_CURRENT));
        }
Пример #3
0
        private PendingIntent getPendingIntent()
        {
            Context ctx    = new Context();
            Intent  intent = new Intent(ctx, BroadcastRegister.CreateLocationReceiver(new LocationBroadcast()));

            intent.setAction(ACTION_PROCESS_LOCATION);
            return(PendingIntent.getBroadcast(ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
        }
Пример #4
0
        public static PendingIntent GetPendingIntent()
        {
            if (mPendingIntent != null)
            {
                return(mPendingIntent);
            }
            Context ctx    = new Context();
            Intent  intent = new Intent(ctx, BroadcastRegister.CreateLocationReceiver(new LocationBroadcast()));

            intent.setAction(ACTION_PROCESS_LOCATION);
            mPendingIntent = PendingIntent.getBroadcast(ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
            return(mPendingIntent);
        }
Пример #5
0
        /// <summary>
        /// Schedule the download of the big picture associated with the content. </summary>
        /// <param name="context"> any application context. </param>
        /// <param name="content"> content with big picture notification. </param>
        public static void downloadBigPicture(Context context, EngagementReachInteractiveContent content)
        {
            /* Set up download request */
            DownloadManager downloadManager = (DownloadManager)context.getSystemService(Context.DOWNLOAD_SERVICE);
            Uri             uri             = Uri.parse(content.NotificationBigPicture);

            DownloadManager.Request request = new DownloadManager.Request(uri);
            request.NotificationVisibility = DownloadManager.Request.VISIBILITY_HIDDEN;
            request.VisibleInDownloadsUi   = false;

            /* Create intermediate directories */
            File dir = context.getExternalFilesDir("engagement");

            dir = new File(dir, "big-picture");
            dir.mkdirs();

            /* Set destination */
            long contentId = content.LocalId;

            request.DestinationUri = Uri.fromFile(new File(dir, contentId.ToString()));

            /* Submit download */
            long id = downloadManager.enqueue(request);

            content.setDownloadId(context, id);

            /* Set up timeout on download */
            Intent intent = new Intent(EngagementReachAgent.INTENT_ACTION_DOWNLOAD_TIMEOUT);

            intent.putExtra(EngagementReachAgent.INTENT_EXTRA_CONTENT_ID, contentId);
            intent.Package = context.PackageName;
            PendingIntent operation       = PendingIntent.getBroadcast(context, (int)contentId, intent, 0);
            long          triggerAtMillis = SystemClock.elapsedRealtime() + DOWNLOAD_TIMEOUT;
            AlarmManager  alarmManager    = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);

            alarmManager.set(ELAPSED_REALTIME_WAKEUP, triggerAtMillis, operation);
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override public Boolean handleNotification(EngagementReachInteractiveContent content) throws RuntimeException
        public virtual bool?handleNotification(EngagementReachInteractiveContent content)
        {
            /* System notification case */
            if (content.SystemNotification)
            {
                /* Big picture handling */
                Bitmap bigPicture    = null;
                string bigPictureURL = content.NotificationBigPicture;
                if (bigPictureURL != null && Build.VERSION.SDK_INT >= 16)
                {
                    /* Schedule picture download if needed, or load picture if download completed. */
                    long?downloadId = content.DownloadId;
                    if (downloadId == null)
                    {
                        EngagementNotificationUtilsV11.downloadBigPicture(mContext, content);
                        return(null);
                    }
                    else
                    {
                        bigPicture = EngagementNotificationUtilsV11.getBigPicture(mContext, downloadId.Value);
                    }
                }

                /* Generate notification identifier */
                int notificationId = getNotificationId(content);

                /* Build notification using support lib to manage compatibility with old Android versions */
                NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);

                /* Icon for ticker and content icon */
                builder.SmallIcon = mNotificationIcon;

                /*
                 * Large icon, handled only since API Level 11 (needs down scaling if too large because it's
                 * cropped otherwise by the system).
                 */
                Bitmap notificationImage = content.NotificationImage;
                if (notificationImage != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                {
                    builder.LargeIcon = scaleBitmapForLargeIcon(mContext, notificationImage);
                }

                /* Texts */
                string notificationTitle   = content.NotificationTitle;
                string notificationMessage = content.NotificationMessage;
                string notificationBigText = content.NotificationBigText;
                builder.ContentTitle = notificationTitle;
                builder.ContentText  = notificationMessage;

                /*
                 * Replay: display original date and don't replay all the tickers (be as quiet as possible
                 * when replaying).
                 */
                long?notificationFirstDisplayedDate = content.NotificationFirstDisplayedDate;
                if (notificationFirstDisplayedDate != null)
                {
                    builder.When = notificationFirstDisplayedDate;
                }
                else
                {
                    builder.Ticker = notificationTitle;
                }

                /* Big picture */
                if (bigPicture != null)
                {
                    builder.Style = (new NotificationCompat.BigPictureStyle()).bigPicture(bigPicture).setBigContentTitle(notificationTitle).setSummaryText(notificationMessage);
                }

                /* Big text */
                else if (notificationBigText != null)
                {
                    builder.Style = (new NotificationCompat.BigTextStyle()).bigText(notificationBigText);
                }

                /* Vibration/sound if not a replay */
                if (notificationFirstDisplayedDate == null)
                {
                    int defaults = 0;
                    if (content.NotificationSound)
                    {
                        defaults |= Notification.DEFAULT_SOUND;
                    }
                    if (content.NotificationVibrate)
                    {
                        defaults |= Notification.DEFAULT_VIBRATE;
                    }
                    builder.Defaults = defaults;
                }

                /* Launch the receiver on action */
                Intent actionIntent = new Intent(INTENT_ACTION_ACTION_NOTIFICATION);
                EngagementReachAgent.setContentIdExtra(actionIntent, content);
                actionIntent.putExtra(INTENT_EXTRA_NOTIFICATION_ID, notificationId);
                Intent intent = content.Intent;
                if (intent != null)
                {
                    actionIntent.putExtra(INTENT_EXTRA_COMPONENT, intent.Component);
                }
                actionIntent.Package = mContext.PackageName;
                PendingIntent contentIntent = PendingIntent.getBroadcast(mContext, (int)content.LocalId, actionIntent, FLAG_CANCEL_CURRENT);
                builder.ContentIntent = contentIntent;

                /* Also launch receiver if the notification is exited (clear button) */
                Intent exitIntent = new Intent(INTENT_ACTION_EXIT_NOTIFICATION);
                exitIntent.putExtra(INTENT_EXTRA_NOTIFICATION_ID, notificationId);
                EngagementReachAgent.setContentIdExtra(exitIntent, content);
                exitIntent.Package = mContext.PackageName;
                PendingIntent deleteIntent = PendingIntent.getBroadcast(mContext, (int)content.LocalId, exitIntent, FLAG_CANCEL_CURRENT);
                builder.DeleteIntent = deleteIntent;

                /* Can be dismissed ? */
                Notification notification = builder.build();
                if (!content.NotificationCloseable)
                {
                    notification.flags |= Notification.FLAG_NO_CLEAR;
                }

                /* Allow overriding */
                if (onNotificationPrepared(notification, content))

                /*
                 * Submit notification, replacing the previous one if any (this should happen only if the
                 * application process is restarted).
                 */
                {
                    mNotificationManager.notify(notificationId, notification);
                }
            }

            /* Activity embedded notification case */
            else
            {
                /* Get activity */
                Activity activity = EngagementActivityManager.Instance.CurrentActivity.get();

                /* Cannot notify in app if no activity provided */
                if (activity == null)
                {
                    return(false);
                }

                /* Get notification area */
                string category             = content.Category;
                int    areaId               = getInAppAreaId(category).Value;
                View   notificationAreaView = activity.findViewById(areaId);

                /* No notification area, check if we can install overlay */
                if (notificationAreaView == null)
                {
                    /* Check overlay is not disabled in this activity */
                    Bundle activityConfig = EngagementUtils.getActivityMetaData(activity);
                    if (!activityConfig.getBoolean(METADATA_NOTIFICATION_OVERLAY, true))
                    {
                        return(false);
                    }

                    /* Inflate overlay layout and get reference to notification area */
                    View overlay = LayoutInflater.from(mContext).inflate(getOverlayLayoutId(category), null);
                    activity.addContentView(overlay, new LayoutParams(MATCH_PARENT, MATCH_PARENT));
                    notificationAreaView = activity.findViewById(areaId);
                }

                /* Otherwise check if there is an overlay containing the area to restore visibility */
                else
                {
                    View overlay = activity.findViewById(getOverlayViewId(category));
                    if (overlay != null)
                    {
                        overlay.Visibility = View.VISIBLE;
                    }
                }

                /* Make the notification area visible */
                notificationAreaView.Visibility = View.VISIBLE;

                /* Prepare area */
                prepareInAppArea(content, notificationAreaView);
            }

            /* Success */
            return(true);
        }