Search in sources :

Example 1 with PendingDynamicLinkData

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]
}
Also used : PendingDynamicLinkData(com.google.firebase.dynamiclinks.PendingDynamicLinkData) TextView(android.widget.TextView) ActivityMainBinding(com.google.firebase.quickstart.deeplinks.databinding.ActivityMainBinding) Uri(android.net.Uri) TextView(android.widget.TextView) View(android.view.View) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Aggregations

Uri (android.net.Uri)1 View (android.view.View)1 TextView (android.widget.TextView)1 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)1 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)1 PendingDynamicLinkData (com.google.firebase.dynamiclinks.PendingDynamicLinkData)1 ActivityMainBinding (com.google.firebase.quickstart.deeplinks.databinding.ActivityMainBinding)1