如何将JSON数据图像共享到WhatsApp Android

时间:2019-07-12 09:52:58

标签: java android json whatsapp

我正在建立一个Android应用程序,该应用程序正在获取文本和图像并显示show,现在我想单击按钮以在whatsapp上共享该图像

下面的我的DetailActivity代码

public class DetailActivity extends AppCompatActivity {

TextView nameTxt,emailTxt, usernameTxt;
ImageView dataImg;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail);

    Button btn_shear =(Button) findViewById(R.id.shear);
    dataImg = (ImageView) findViewById(R.id.iv_preview_image);
    nameTxt = (TextView) findViewById(R.id.nameDetailTxt);

    //GET INTENT
    Intent i=this.getIntent();

    //RECEIVE DATA
    String name=i.getExtras().getString("TITILE_KEY");
    final String img=i.getExtras().getString("IMG_KEY");

    //BIND DATA
    nameTxt.setText(name);
    PicassoClient.downloadImage(this,img,dataImg);

    btn_shear.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Uri imgUri = Uri.parse(img);
            Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
            whatsappIntent.setType("text/plain");
            whatsappIntent.setPackage("com.whatsapp");
            whatsappIntent.putExtra(Intent.EXTRA_TEXT, "The text you wanted to share");
            whatsappIntent.putExtra(Intent.EXTRA_STREAM, imgUri);
            whatsappIntent.setType("image/jpeg");
            whatsappIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }
    });     
}
}

0 个答案:

没有答案