Share app link with Whatsapp

Asked

Viewed 3,946 times

0

Good morning ! How do I share a link from my app with a contact in Whatsapp ? Searching on the internet I was able to form this code (it is without successful tests because I’m still just testing it) that when recording an activity in firebase I open a library full of apps to share a link, but so far I can only share the text: "User x has created a new activity, what I’d like is for this message to have a link that directs the person directly to the profile or to any screen of my app for example. Follows code (from Activity’s Website) that shares the text cited above:

public void compartilharAtividade(){

    Branch branch = Branch.getInstance();
    //Uri mainUri = getActivity().getIntent().getData();
    Intent share = new Intent(android.content.Intent.ACTION_SEND);
    share.setType("text/plain");
    share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

    share.putExtra(Intent.EXTRA_SUBJECT, "Teste de compartilhamento APP");
    share.putExtra(Intent.EXTRA_TEXT, "O usuario "+ nomeUsuario + " criou uma nova atividade! Teste de Link: "+ branch);
    //share.putExtra(Intent.EXTRA_PACKAGE_NAME, "com.ramattecgmail.rafah.studying");

    startActivity(Intent.createChooser(share, "Teste de compartilhamento"));

}

in Main Activity I call the branch this way:

@Override
public void onStart() {
    super.onStart();
    Branch branch = Branch.getInstance();

    branch.initSession(new Branch.BranchUniversalReferralInitListener() {
        @Override
        public void onInitFinished(BranchUniversalObject branchUniversalObject, LinkProperties linkProperties, BranchError error) {
            if (error == null) {
                // params are the deep linked params associated with the link that the user clicked -> was re-directed to this app
                // params will be empty if no data found
                // ... insert custom logic here ...
            } else {
                Log.i("MyApp", error.getMessage());
            }
        }
    }, this.getIntent().getData(), this);
}

@Override
public void onNewIntent(Intent intent) {
    this.setIntent(intent);
}

In short, I need my app to send the Uri itself, or at least recover this Uri that I can’t even do in Main Activity... Thanks in advance!

  • Do you have any specific link ?

  • Actually not exactly, it’s the first time I’m messing with sharing like this, so I may be wrong about some things, but I think it should work as follows: send a message to the person with a link that when they click will direct to the app in the profile Activity that will load the data of the user I pass in the message, or in this case with a link of the activity that was opened... briefly, by clicking on the link of the message it opens my app.

  • if you send a link it will redirect to a web page, not to your app

  • So how do I direct you to my app? It’s possible ?

  • It’s possible, you’ll have a little work hehe, I’ll do a quick research and I’ll be right back to help you

1 answer

1


Good you will have to create a deep link and add in the manifest of your Activity, for example:

<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
    android:host="www.seusite.com"
    android:pathPrefix="/home"
    android:scheme="https"/>
</intent-filter>

Where is the host, you will add your URL, to redirect to your app link, but first of all do not forget to add android-app://yourpackage name/http/www.seusite.com/home/ so it recognizes the package of your app.

This link will certainly help you understand a little more about deep link:

https://www.youtube.com/watch?v=YuWQUAi7d9I

  • Thank you very much Matheus, already served me as a north study on deep links, but now, how do I share this link via Whatsapp message as an Intent putExtra? I want to share this host created with whattsApp

  • If the answer is correct don’t forget to mark it as correct =) haha.. Okay just a minute to a half Done here but I’ll be back to help you

  • Make the following friend, creates a button and at the click of that button you call your sharing method Activity, when you click the button will appear all the apps that you can share that are installed on your device, after that just click on the desired application and on the putextra you put your package/http://www.seusite.com/home

  • Matheus, sedei sobrgui seus conselhos e estue banch.io however my question has not been clearly answered, I have done several tests but still can not send the Language of my app to a contact whatts where it click and is directed to my app.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.