How to add Custom Text instead of URL in Deeplink message

I’m integrating Firebase to support Deeplink feature in app. I have seen in one of screen-example suggested(PFA) here that we can add our own custom text instead of display Deep link URL.

enter image description here

  • Cannot get android MediaPlayer onCompletion to fire
  • Get contact name given a phone number in Android
  • How to update contact number using Android
  • Android usb host api and USB storage
  • how to develop a simple android streaming audio player?
  • Why does DrawerLayout sometimes glitch upon opening?
  • I have tried to update but that did not help. How to do that, Any suggestion?

    Related posts:

    How to avoid reverse engineering of an APK file?
    How to get RelativeLayout working with merge and include?
    Programming my android application with Gimbal sdk doesn't detect the gimbal beacon
    Remove show password icon in Android N
    Scrollbar not showing in RecyclerView
    How to share cookie data in chrome custom tabs android
  • How to retrive all rows of ParseObject in android
  • Dismiss Ongoing Android Notification Via Action Button Without Opening App
  • How to add “Next” on android keyboard
  • Change Circle color of radio button- Android
  • Give text of selected tab a different color using ViewPagerIndicator
  • PictureListener and onNewPicture() are deprecated - Alternatives?
  • 2 Solutions collect form web for “How to add Custom Text instead of URL in Deeplink message”

    My guess is that you are using a UITextView for when the user enters text (in iOS). Here is how to accomplish that in Swift:

    class ViewController: UIViewController {
    
        @IBOutlet weak var textView: UITextView!
        @IBOutlet weak var textField: UITextField!
    
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.
        }
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
    
        @IBAction func buttonPress(_ sender: Any) {
            let range = textView.selectedRange
            let linkString = NSMutableAttributedString(string: textView.text)
            linkString.addAttribute(NSLinkAttributeName, value: textField.text ?? "", range: range)
            textView.attributedText = linkString
        }
    
    }
    
    extension ViewController: UITextViewDelegate {
        func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
            UIApplication.shared.open(URL, options: [:], completionHandler: nil)
            return false
        }
    }
    

    In Android, I found a couple of SO answers that seem to handle the topic well:

    Make a hyperlink textview in android

    From user370305:

    Try this, and let me know what happen..

    TextView textView =(TextView)findViewById(R.id.textView);
    textView.setClickable(true);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    String text = "<a href='http://www.google.com'> Google </a>";
    textView.setText(Html.fromHtml(text));
    

    Put html link in edittext android

    From RobinHood:

    Put your html in a string@

    <string url="link">&lt;a href="http://www.google.com">Google&lt;/a></string>
    

    set String to editText@

    youredittext.setText(Html.fromHtml(getResources().getString(R.string.url)));
    

    For click, set LinkMovementMethod with necessary action@

    youredittext.setMovementMethod(LinkMovementMethod.getInstance());
    

    If you are trying to accomplish this in HTML, then use an anchor (a) tag:

    <p>Click on this <a href="https://stackoverflow.com/">Link</a></p>

    I have done the same thing in one of my apps. Please follow below code.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/activity_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="@dimen/margin"
        tools:context="tdsolutions.com.clickabletext.MainActivity">
    
        <TextView
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World this text" />
    
    </LinearLayout>
    

    Pass your Textview to below method(setClickableText):

    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
    
      TextView text = (TextView) findViewById(R.id.text);
      setClickableText(text);
    }
    
    private void setClickableText(TextView textView) {
            String text = "this"; // the text you want to mark as a link
    
            SpannableString ss = new SpannableString(textView.getText());// full text
            final ForegroundColorSpan fcs = new ForegroundColorSpan(Color.parseColor("#91ca46"));//link text color
    
            ClickableSpan clickableSpan = new ClickableSpan() {
                @Override
                public void onClick(View textView) {
                    //What ever the code you want when click on text goes here
                    Toast.makeText(MainActivity.this,"you clicked",Toast.LENGTH_LONG).show();
                }
    
                @Override
                public void updateDrawState(TextPaint ds) {
                    super.updateDrawState(ds);
                    ds.setUnderlineText(false);
                }
            };
    
            int start = textView.getText().toString().indexOf(text);
            int length = start + text.length();
    
            ss.setSpan(clickableSpan, start, length, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            ss.setSpan(fcs, start, length, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            textView.setText(ss);
            textView.setMovementMethod(LinkMovementMethod.getInstance());
            textView.setHighlightColor(Color.TRANSPARENT);
        }
    

    Or you can use below code:

    Add the text view as below, change whatever the attributes as you wish.

       <TextView
            android:id="@+id/textView"
            android:layout_centerInParent="true"
            android:linksClickable="true"
            android:textColorLink="#00f"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    

    then add below code:

    TextView textView = (TextView) findViewById(R.id.textView);
    Spanned result;
    String html = "Hi sweetheart go to <a href=\"http://www.google.com\">this</a> link";
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
        result = Html.fromHtml(html ,Html.FROM_HTML_MODE_LEGACY);
    } else {
        result = Html.fromHtml(html);
    }
    textView.setText(result);
    textView. setMovementMethod(LinkMovementMethod.getInstance());
    

    please make sure when you add links replace them with html tags as I did in the example String html = "Hi sweetheart go to <a href=\"http://www.google.com\">this</a> link";

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.