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);
        }
Ejemplo n.º 4
0
        /// <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);
        }