以下是从playstore安装后接收promocode的代码
FacebookSdk.sdkInitialize(getApplicationContext());
Uri targetUrl = AppLinks.getTargetUrlFromInboundIntent(this, getIntent());
if (targetUrl != null)
{
Log.i("facebook_app_invite","if");
Log.i("Activity", "App Link Target URL: " + targetUrl.toString());
}
else
{
AppLinkData.fetchDeferredAppLinkData(getApplicationContext(),new AppLinkData.CompletionHandler()
{
@Override
public void onDeferredAppLinkDataFetched(AppLinkData appLinkData)
{
//process applink data
Log.i("facebook_app_invite","else");
if (appLinkData != null)
{
Log.i("facebook_app_invite",appLinkData.getPromotionCode());
String promoCode = appLinkData.getPromotionCode();
if (promoCode != null)
{
Log.i("facebook_app_invite",promoCode.toString());
// ... execute code related to the promotion ...
}
}
else
{
System.out.println("appLinkData is null");
Log.i("facebook_app_invite", "appLinkData is null");
}
}
});
}
我使用以下代码发送Facebook应用邀请
try
{
CallbackManager sCallbackManager = CallbackManager.Factory.create();
if (AppInviteDialog.canShow())
{
AppInviteContent content = new AppInviteContent.Builder()
.setApplinkUrl(appLinkUrl)
.setPreviewImageUrl(previewImageUrl)
.setPromotionDetails("Promotional Message", "promocode").build();
AppInviteDialog appInviteDialog = new AppInviteDialog(Ced_SharePage.this);
appInviteDialog.registerCallback(sCallbackManager,new FacebookCallback<AppInviteDialog.Result>()
{
@Override
public void onSuccess(AppInviteDialog.Result result)
{
Log.d("Invitation", "Invitation Sent Successfully");
finish();
}
@Override
public void onCancel()
{
Log.d("Invitation", "Cancel");
}
@Override
public void onError(FacebookException e)
{
Log.d("Invitation", "Error Occured");
}
});
appInviteDialog.show(content);
}
}
catch (Exception e)
{
}
当我发送Facebook应用邀请时,Facebook应用会显示通知并提示用户安装应用,安装应用后,当我们尝试获取appLinkData时返回null