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. */ } } } }
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 ADM registration identifier if enabled, this is asynchronous, the response is made * via a broadcast intent with the <tt>com.amazon.device.messaging.intent.REGISTRATION</tt> * action. */ if (EngagementUtils.getMetaData(context).getBoolean("engagement:adm:register")) { try { Type admClass = Type.GetType("com.amazon.device.messaging.ADM"); object adm = admClass.GetConstructor(typeof(Context)).newInstance(context); admClass.GetMethod("startRegister").invoke(adm); } catch (Exception) { /* Abort if ADM not available */ } } } }
/// <summary> /// Init default notifier. </summary> /// <param name="context"> any application context. </param> public EngagementDefaultNotifier(Context context) { /* Init */ mContext = context.ApplicationContext; mNotificationManager = (NotificationManager)context.getSystemService(NOTIFICATION_SERVICE); /* Get icon identifiers from AndroidManifest.xml */ Bundle appMetaData = EngagementUtils.getMetaData(context); mNotificationIcon = getIcon(appMetaData, METADATA_NOTIFICATION_ICON); }
/// <summary> /// Init the agent. </summary> /// <param name="context"> application context. </param> private EngagementAgent(Context context) { if (!InstanceFieldsInitialized) { InitializeInstanceFields(); InstanceFieldsInitialized = true; } /* Store application context, we'll use this to bind */ mContext = context; /* Create main thread handler */ mHandler = new Handler(Looper.MainLooper); /* Retrieve configuration */ Bundle config = EngagementUtils.getMetaData(context); mReportCrash = config.getBoolean("engagement:reportCrash", true); string settingsFile = config.getString("engagement:agent:settings:name"); int settingsMode = config.getInt("engagement:agent:settings:mode", 0); if (TextUtils.isEmpty(settingsFile)) { settingsFile = "engagement.agent"; } /* Watch preferences */ mSettings = context.getSharedPreferences(settingsFile, settingsMode); mSettingsListener = new OnSharedPreferenceChangeListenerAnonymousInnerClassHelper(this); mSettings.registerOnSharedPreferenceChangeListener(mSettingsListener); /* Install Engagement crash handler if enabled */ if (mReportCrash) { Thread.DefaultUncaughtExceptionHandler = mEngagementCrashHandler; } /* Broadcast intent for Engagement modules */ Intent agentCreatedIntent = new Intent(INTENT_ACTION_AGENT_CREATED); agentCreatedIntent.Package = context.PackageName; context.sendBroadcast(agentCreatedIntent); }
//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); }