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

前端 未结 11 1866
隐瞒了意图╮
隐瞒了意图╮ 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:04

    Check the below code it worked for me

        Picasso.with(getApplicationContext()).load("image url path").into(new Target() {
    
               @Override
    
                public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                    Intent i = new Intent(Intent.ACTION_SEND);
                    i.putExtra(Intent.EXTRA_TEXT, "Let me recommend you this application" +
                            "\n"+ "your share url or text ");
                    i.setType("image/*");
                    i.putExtra(Intent.EXTRA_STREAM, getLocalBitmapUri(bitmap));
                    context.startActivity(Intent.createChooser(i, "Share using"));
                }
    
                @Override
                public void onBitmapFailed(Drawable errorDrawable) {
                }
    
                @Override
                public void onPrepareLoad(Drawable placeHolderDrawable) {
                }
            });
    
    
         private Uri getLocalBitmapUri(Bitmap bmp) {
          Uri bmpUri = null;
          try {
              File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "share_image_" + System.currentTimeMillis() + ".png");
            FileOutputStream out = new FileOutputStream(file);
            bmp.compress(Bitmap.CompressFormat.PNG, 50, out);
            out.close();
            bmpUri = Uri.fromFile(file);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return bmpUri;
    }
    

提交回复
热议问题