Search code examples
androidfacebookmessagewhatsappinvite

Android : How to send app invite message using whatsapp,facebook,gmail,etc from my app


I need to send app invitation message from my app to friends via whatsapp,facebook,hike,... with the message and playstore link.I have seen this kind of invitations in other apps like hike,whatscall,... like the attached image below. hike and whatscall

I want to send exactly the same kind of message with the playstore link and app logo for my app also and it should be shared using all the available sharing option in users mobile.In my application i have included a inform friends menu and on clicking on that this function should work.I have seen firebase app invite examples but it needs google-services.json and i think it will only send text message from users email,I am not sure about that.


Solution

  • You need to create an intent as follows which will allow you to share your app using any other app :

        try { 
            Intent i = new Intent(Intent.ACTION_SEND);  
            i.setType("text/plain");
            i.putExtra(Intent.EXTRA_SUBJECT, "My app name");
            String strShareMessage = "\nLet me recommend you this application\n\n";
            strShareMessage = strShareMessage + "https://play.google.com/store/apps/details?id=" + getPackageName();
            Uri screenshotUri = Uri.parse("android.resource://packagename/drawable/image_name");
            i.setType("image/png");
            i.putExtra(Intent.EXTRA_STREAM, screenshotUri);
            i.putExtra(Intent.EXTRA_TEXT, strShareMessage);  
            startActivity(Intent.createChooser(i, "Share via"));
        } catch(Exception e) { 
            //e.toString();
        }