How to Share Image + Text together using ACTION_SEND in android?

前端 未结 11 1871
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 09:59

I want to share Text + Image together using ACTION_SEND in android, I am using below code, I can share only Image but i can not share Text with it,

private          


        
11条回答
  •  眼角桃花
    2020-11-28 10:18

    please have a look on this code worked for me to share an text and image together

    Intent shareIntent;
        Bitmap bitmap= BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher);
        String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)+"/Share.png";
        OutputStream out = null;
        File file=new File(path);
        try {
            out = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        path=file.getPath();
        Uri bmpUri = Uri.parse("file://"+path);
        shareIntent = new Intent(android.content.Intent.ACTION_SEND);
        shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
        shareIntent.putExtra(Intent.EXTRA_TEXT,"Hey please check this application " + "https://play.google.com/store/apps/details?id=" +getPackageName());
        shareIntent.setType("image/png");
        startActivity(Intent.createChooser(shareIntent,"Share with"));
    

    Don't forget to give WRITE_EXTERNAL_STORAGE Permission

    also in facebook it can only share the image because facebook is not allowing to share the text via intent

提交回复
热议问题