Share App Link with WhatsApp

0

Good morning!    How do I share a link from my app with a contact in whatsapp? Searching the internet was able to form this code (it is without success tests because I am still just testing it) that when recording an activity in the firebase I open a library full of apps to be able to share a link, but so far I I can only share the text: "User x created a new activity, what I would like is that this message had a link that directed the person directly to the profile or to any screen of my app for example. Here is the code (from the Activity fragment) that shares the text quoted 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 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 uri to itself, or at least retrieve that Uri that I can not even do in Main Activity ... Thank you!

    
asked by anonymous 20.09.2017 / 16:18

1 answer

1

Well 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 be sure to add android-app: // yourpackage name / http / www.yourite.com / home / so that it recognizes the package of your app.

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

link

    
20.09.2017 / 16:25