您可以在链接中添加额外参数以从 Firebase 生成短网址。在这里,我给出了使用 Firebase API 生成短 URL 的示例。这里 ServiceRequestHelper(this).PostCall 是我发出 API 请求的通用类
String url = "https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=YOUR_KEY";
try {
PackageManager manager = this.getPackageManager();
PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
JSONObject jsonObject = new JSONObject();
JSONObject androidInfoObject = new JSONObject();
androidInfoObject.put("androidPackageName", getApplicationContext().getPackageName());
androidInfoObject.put("androidMinPackageVersionCode",String.valueOf(info.versionCode));
JSONObject iosInfoObject = new JSONObject();
iosInfoObject.put("iosBundleId", "tettares.Test_ID");
JSONObject dynamicLinkInfoObj = new JSONObject();
dynamicLinkInfoObj.put("dynamicLinkDomain", "wgv3v.app.goo.gl");
dynamicLinkInfoObj.put("link", "https://test.in/?UserId=14&UserName=Naveen"); // Pass your extra paramters to here
dynamicLinkInfoObj.put("androidInfo", androidInfoObject);
dynamicLinkInfoObj.put("iosInfo", iosInfoObject);
JSONObject suffixObject = new JSONObject();
suffixObject.put("option" , "SHORT");
jsonObject.put("dynamicLinkInfo", dynamicLinkInfoObj);
jsonObject.put("suffix", suffixObject);
Log.d("JSON Object : " , jsonObject.toString());
new ServiceRequestHelper(this).PostCall(url, jsonObject, false, new CallBackJson() {
@Override
public void done(JSONObject result) throws JSONException {
try {
if (result.has("shortLink")) {
DEEP_LINK_URL = result.getString("shortLink"); }
} catch(Exception e)
{
e.printStackTrace();
}
}
});
} catch (JSONException | PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
在您的接收活动中:
boolean autoLaunchDeepLink = false;
AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, this, autoLaunchDeepLink)
.setResultCallback(
new ResultCallback<AppInviteInvitationResult>() {
@Override
public void onResult(@NonNull AppInviteInvitationResult result) {
if (result.getStatus().isSuccess()) {
// Extract deep link from Intent
Intent intent = result.getInvitationIntent();
String deepLink = AppInviteReferral.getDeepLink(intent);
// Handle the deep link. For example, open the linked
// content, or apply promotional credit to the user's
// account.
// [START_EXCLUDE]
// Display deep link in the UI
Log.d(TAG, "deeplink URL: " + deeplink); // Here you get https://test.in/?UserId=14&UserName=Naveen
// [END_EXCLUDE]
} else {
Log.d(TAG, "getInvitation: no deep link found.");
}
}
});