public override void OnReceive(Context context, Intent intent) { var deepLinkIntent = AppInviteReferral.AddPlayStoreReferrerToIntent(intent, new Intent(context.GetString(Resource.String.action_deep_link))); LocalBroadcastManager.GetInstance(context).SendBroadcast(deepLinkIntent); }
void ProcessReferralIntent(Intent intent) { if (!AppInviteReferral.HasReferral(intent)) { Log.Error(Tag, "Error: DeepLinkActivity Intent does not contain App Invite"); return; } var invitationId = AppInviteReferral.GetInvitationId(intent); var deepLink = AppInviteReferral.GetDeepLink(intent); Log.Debug(Tag, "Found Referral: " + invitationId + ":" + deepLink); (FindViewById <TextView> (Resource.Id.deep_link_text)).Text = string.Format(deepLink, GetString(Resource.String.deep_link_fmt)); (FindViewById <TextView> (Resource.Id.invitation_id_text)).Text = string.Format(invitationId, GetString(Resource.String.invitation_id_fmt)); if (googleApiClient.IsConnected) { UpdateInvitationStatus(intent); } else { Log.Warn(Tag, "Warning: GoogleAPIClient not connected, can't update invitation."); cachedInvitationIntent = intent; } }
void ProcessReferralIntent(Intent intent) { if (!AppInviteReferral.HasReferral(intent)) { if (needsRefresh) { RefreshData(); } return; } Xamarin.Insights.Track("AppInvite-Accepted"); var invitationId = AppInviteReferral.GetInvitationId(intent); var deepLink = AppInviteReferral.GetDeepLink(intent); Console.WriteLine("Referral found: invitationId: " + invitationId + " deepLink: " + deepLink); var info = deepLink.Replace("http://motzcod.es/coffee/", string.Empty); viewModel.Place.PlaceId = info; RefreshData(); if (client.IsConnected) { UpdateInvitationStatus(intent); } else { Console.WriteLine("Warning: GoogleAPIClient not connect, can't update invitation just yet."); cachedInvitationIntent = intent; } }
/// <summary> /// Update the install and conversion status of an invite intent /// </summary> /// <param name="intent">Intent.</param> private void UpdateInvitationStatus(Intent intent) { var invitationId = AppInviteReferral.GetInvitationId(intent); // Note: these calls return PendingResult(s), so one could also wait to see // if this succeeds instead of using fire-and-forget, as is shown here if (AppInviteReferral.IsOpenedFromPlayStore(intent)) { Xamarin.Insights.Track("AppInvite", new Dictionary <string, string> { { "status", "new_install" } }); AppInviteClass.AppInviteApi.UpdateInvitationOnInstall(client, invitationId); } else { Xamarin.Insights.Track("AppInvite", new Dictionary <string, string> { { "status", "installed" } }); } // If your invitation contains deep link information such as a coupon code, you may // want to wait to call `convertInvitation` until the time when the user actually // uses the deep link data, rather than immediately upon receipt AppInviteClass.AppInviteApi.ConvertInvitation(client, invitationId); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); #if DEBUG Xamarin.Insights.Initialize("ef02f98fd6fb47ce8624862ab7625b933b6fb21d", this); #else Xamarin.Insights.Initialize("8da86f8b3300aa58f3dc9bbef455d0427bb29086", this); #endif mapView = FindViewById <MapView> (Resource.Id.map); mapView.OnCreate(bundle); mapView.Visibility = ViewStates.Invisible; viewModel = new CoffeeFilterViewModel(); ServiceContainer.Register <CoffeeFilterViewModel> (viewModel); adapter = new PlacesPagerAdapter(SupportFragmentManager, viewModel); pager = FindViewById <ViewPager> (Resource.Id.pager); pager.Adapter = adapter; progressBar = FindViewById <ImageView> (Resource.Id.progressBar); errorImage = FindViewById <ImageView> (Resource.Id.error); coffeeProgress = (AnimationDrawable)progressBar.Background; progressBar.Visibility = ViewStates.Gone; pager.PageSelected += (sender, e) => UpdateMap(e.Position); pager.PageScrollStateChanged += (sender, e) => { if (e.State == (int)ScrollState.TouchScroll) { refresher.Enabled = false; } else { refresher.Enabled = true; } }; refresher = FindViewById <SwipeRefreshLayout> (Resource.Id.refresher); refresher.SetColorSchemeColors(Resource.Color.accent); refresher.Refresh += (sender, args) => { RefreshData(true); refresher.PostDelayed(() => { refresher.Refreshing = false; }, 250); }; SupportActionBar.SetDisplayHomeAsUpEnabled(false); SupportActionBar.SetHomeButtonEnabled(false); mapView.GetMapAsync(this); CheckGooglePlayServices(); // No savedInstanceState, so it is the first launch of this activity if (bundle == null && AppInviteReferral.HasReferral(Intent)) { // In this case the referral data is in the intent launching the MainActivity, // which means this user already had the app installed. We do not have to // register the Broadcast Receiver to listen for Play Store Install information LaunchDeepLinkActivity(Intent); } }
public override void OnReceive(Context context, Intent intent) { if (!AppInviteReferral.HasReferral(intent)) { return; } activity.LaunchDeepLinkActivity(intent); }
public override void OnReceive(Context context, Intent intent) { // Create deep link intent with correct action and add play store referral information var deepLinkIntent = AppInviteReferral.AddPlayStoreReferrerToIntent(intent, new Intent(context.GetString(Resource.String.action_deep_link))); // Let any listeners know about the change LocalBroadcastManager.GetInstance(context).SendBroadcast(deepLinkIntent); }
async Task UpdateInvitationStatus(Intent intent) { var invitationId = AppInviteReferral.GetInvitationId(intent); if (AppInviteReferral.IsOpenedFromPlayStore(intent)) { await AppInviteClass.AppInviteApi.UpdateInvitationOnInstallAsync(googleApiClient, invitationId); } await AppInviteClass.AppInviteApi.ConvertInvitationAsync(googleApiClient, invitationId); }
void UpdateInvitationStatus(Intent intent) { var invitationId = AppInviteReferral.GetInvitationId(intent); if (AppInviteReferral.IsOpenedFromPlayStore(intent)) { AppInviteClass.AppInviteApi.UpdateInvitationOnInstall(googleApiClient, invitationId); } AppInviteClass.AppInviteApi.ConvertInvitation(googleApiClient, invitationId); }
// [START deep_link_on_start] protected override void OnStart() { base.OnStart(); // Check if the intent contains an AppInvite and then process the referral information. Intent intent = Intent; if (AppInviteReferral.HasReferral(intent)) { ProcessReferralIntent(intent); } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); var button = FindViewById <Button> (Resource.Id.buttonInvite); button.Click += delegate { SendAppInvite(); }; googleApiClient = new GoogleApiClient.Builder(this) .AddApi(AppInviteClass.API) .AddConnectionCallbacks(async info => { if (AppInviteReferral.HasReferral(Intent)) { await UpdateInvitationStatus(Intent); } }, cause => Console.WriteLine("Connection Suspended: {0}", cause)) .AddOnConnectionFailedListener(result => { if (!result.IsSuccess) { if (result.HasResolution) { result.StartResolutionForResult(this, RESOLUTION_CODE); } else { Toast.MakeText(this, "Failed to Connect: " + result.ErrorCode, ToastLength.Long).Show(); } } }) .Build(); // If the app was already installed and the appinvite was opened // we may have information passed in about it here if (bundle == null) { // No savedInstanceState, so it is the first launch of this activity if (AppInviteReferral.HasReferral(Intent)) { // In this case the referral data is in the intent launching the MainActivity, // which means this user already had the app installed. We do not have to // register the Broadcast Receiver to listen for Play Store Install information LaunchDeepLinkActivity(Intent); } } }
void RegisterDeepLinkReceiver() { deepLinkReceiver = new BroadcastReceiver(); deepLinkReceiver.OnReceiveImpl = (context, intent) => { if (AppInviteReferral.HasReferral(intent)) { LaunchDeepLinkActivity(intent); } }; var intentFilter = new IntentFilter(GetString(Resource.String.action_deep_link)); LocalBroadcastManager.GetInstance(this).RegisterReceiver( deepLinkReceiver, intentFilter); }
// [END deep_link_on_start] // [START process_referral_intent] private void ProcessReferralIntent(Intent intent) { // Extract referral information from the intent string invitationId = AppInviteReferral.GetInvitationId(intent); string deepLink = AppInviteReferral.GetDeepLink(intent); // Display referral information // [START_EXCLUDE] Console.WriteLine(TAG, "Found Referral: " + invitationId + ":" + deepLink); ((TextView)FindViewById(Resource.Id.deep_link_text)) .SetText(Resource.String.deep_link_fmt); ((TextView)FindViewById(Resource.Id.invitation_id_text)) .SetText(Resource.String.invitation_id_fmt); // [END_EXCLUDE] }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.main_activity); FindViewById(Resource.Id.invite_button).SetOnClickListener(this); if (savedInstanceState == null) { var intent = Intent; if (AppInviteReferral.HasReferral(intent)) { LaunchDeepLinkActivity(intent); } } }
async Task UpdateInvitationStatus(Intent intent) { var invitationId = AppInviteReferral.GetInvitationId(intent); // Note: these calls return PendingResult(s), so one could also wait to see // if this succeeds instead of using fire-and-forget, as is shown here if (AppInviteReferral.IsOpenedFromPlayStore(intent)) { await AppInviteClass.AppInviteApi.UpdateInvitationOnInstallAsync(googleApiClient, invitationId); } // If your invitation contains deep link information such as a coupon code, you may // want to wait to call `convertInvitation` until the time when the user actually // uses the deep link data, rather than immediately upon receipt await AppInviteClass.AppInviteApi.ConvertInvitationAsync(googleApiClient, invitationId); }
void RegisterDeepLinkReceiver() { // Create local Broadcast receiver that starts DeepLinkActivity when a deep link // is found deepLinkReceiver = new LocalBroadcastReceiver { OnReceiveHandler = (context, intent) => { if (AppInviteReferral.HasReferral(intent)) { LaunchDeepLinkActivity(intent); } } }; var intentFilter = new IntentFilter(GetString(Resource.String.action_deep_link)); LocalBroadcastManager.GetInstance(this).RegisterReceiver(deepLinkReceiver, intentFilter); }
// [END define_variables] // [START on_create] protected override void OnCreate(Bundle savedInstanceState) { // [START_EXCLUDE] base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.main_activity); // Invite button click listener FindViewById(Resource.Id.invite_button).SetOnClickListener(this); // [END_EXCLUDE] // Create an auto-managed GoogleApiClient with access to App Invites. mGoogleApiClient = new GoogleApiClient.Builder(this) .AddApi(AppInviteClass.API) .EnableAutoManage(this, this) .Build(); // Check for App Invite invitations and launch deep-link activity if possible. // Requires that an Activity is registered in AndroidManifest.xml to handle // deep-link URLs. bool autoLaunchDeepLink = true; AppInviteClass.AppInviteApi.GetInvitation(mGoogleApiClient, this, autoLaunchDeepLink) .SetResultCallback( new ResultCallback <IAppInviteInvitationResult>((IAppInviteInvitationResult result) => { Console.WriteLine(TAG, string.Format("getInvitation:onResult:{0}", result.Status)); if (result.Status.IsSuccess) { // Extract information from the intent Intent intent = result.InvitationIntent; String deepLink = AppInviteReferral.GetDeepLink(intent); String invitationId = AppInviteReferral.GetInvitationId(intent); // Because autoLaunchDeepLink = true we don't have to do anything // here, but we could set that to false and manually choose // an Activity to launch to handle the deep link here. // ... } })); }