Search code examples
androidandroid-intentinvite

How to properly create an Intent to refer like Tez?


In my app i have to add an intent to share my app. I looked through Tez, which shares the app icon along with a text which contains a hyperlink. How to achieve this?enter image description here


Solution

  • private void prepareShareIntent(Bitmap bmp) {
            Uri bmpUri = getLocalBitmapUri(bmp); // see previous remote images section
            // Construct share intent as described above based on bitmap
    
            Intent shareIntent = new Intent();
            shareIntent = new Intent();
            shareIntent.setPackage("com.whatsapp");
            shareIntent.setAction(Intent.ACTION_SEND);
    
            shareIntent.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.share_app)  );
            shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
            shareIntent.setType("image/*");
            shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            startActivity(Intent.createChooser(shareIntent, "Share Opportunity"));
    
        }
    
    private Uri getLocalBitmapUri(Bitmap bmp) {
            Uri bmpUri = null;
            File file = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), "share_image_" + System.currentTimeMillis() + ".png");
            FileOutputStream out = null;
            try {
                out = new FileOutputStream(file);
                bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                bmpUri = Uri.fromFile(file);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            return bmpUri;
        }