Share app link with WhatsApp

Good Morning ! How do I share a link from my app with a contact on whatsapp ? Searching on the internet I managed to form this code(it is without successful tests why I'm still just testing it) that by recording an activity in firebase I open a library full of apps to be able to share a link, but so far I can only share the text: "user x created a new activity, what I would like is that have a link that would direct the person directly to the profile or to any screen of my app for example. It follows code (from the activity fragment) 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 the main Activity I call the branch like this:

@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 retrieve that Uri that I can't even do in Main Activity... I appreciate it now!

Author: Eduardo Rafael Moraes, 2017-09-20

1 answers

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 its 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 that the same recognizes the package of your app.

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

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

 1
Author: Dev, 2017-09-20 14:43:12