我想通过电子邮件等分享时出错

时间:2018-06-24 15:07:25

标签: android share

因此,当我单击“共享”按钮时,没有错误,或者我的应用没有崩溃,但是弹出消息显示:

通过ClipData.Item.getUri()在应用之外公开的文件//存储/仿真/0/Android/data/com.project.sandyapp/cache/sampe.png。

你知道这是什么吗?

这是我的共享方法:

  //Share Button click
    mShareBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            shareImage();
        }
    });

}

private void shareImage() {
    try {
        //Get title, description, price, category and save in string
        String s = detTitleTv.getText().toString() + "\n" + detDescriptionTv.getText().toString()
                + "\n" + detPriceTv.getText().toString() + "\n" + detCategoryTv.getText().toString()
                + "\n" + detLocationTv.getText().toString();

        File file = new File(getExternalCacheDir(), "sample.png");
        FileOutputStream fOut = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
        fOut.flush();
        fOut.close();
        file.setReadable(true,false);
        //Intent to share image and text
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(Intent.EXTRA_TEXT, s);//Put the text
        intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
        intent.setType("image/png");
        startActivity(Intent.createChooser(intent,"Share via"));

    } catch (Exception e) {
        Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
    }

0 个答案:

没有答案