use of com.google.firebase.dynamiclinks.PendingDynamicLinkData in project quickstart-android by firebase.
the class MainActivity method onCreate.
// [START on_create]
@Override
protected void onCreate(Bundle savedInstanceState) {
// [START_EXCLUDE]
super.onCreate(savedInstanceState);
ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
TextView linkSendTextView = binding.linkViewSend;
final TextView linkReceiveTextView = binding.linkViewReceive;
// Validate that the developer has set the app code.
validateAppCode();
// Create a deep link and display it in the UI
final Uri deepLink = buildDeepLink(Uri.parse(DEEP_LINK_URL), 0);
linkSendTextView.setText(deepLink.toString());
// Share button click listener
binding.buttonShare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
shareDeepLink(deepLink.toString());
}
});
// [END_EXCLUDE]
// [START get_deep_link]
FirebaseDynamicLinks.getInstance().getDynamicLink(getIntent()).addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
@Override
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
// Get deep link from result (may be null if no link is found)
Uri deepLink = null;
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
}
// Display deep link in the UI
if (deepLink != null) {
Snackbar.make(findViewById(android.R.id.content), "Found deep link!", Snackbar.LENGTH_LONG).show();
linkReceiveTextView.setText(deepLink.toString());
} else {
Log.d(TAG, "getDynamicLink: no link found");
}
// [END_EXCLUDE]
}
}).addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w(TAG, "getDynamicLink:onFailure", e);
}
});
// [END get_deep_link]
}
Aggregations