1

嘿,我想将我在 imageview 中的图像分享到 instagram,并且在我想分享图像之前使用 ACTION_SEND 我从其他活动中获取我的图片

我运行应用程序并收到消息“无法下载文件”

这是我的代码....如果有任何错误,请检查我的代码

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.io.File;

public class editPhoto extends Activity {

    String picturePath;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        overridePendingTransition(R.anim.push_left_in, R.anim.hold);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.page);

        picturePath = getIntent().getStringExtra("selectedPhoto");

        Bitmap bitmap = BitmapFactory.decodeFile(picturePath);
        ImageView imageView = (ImageView) findViewById(R.id.iv_pic);
        imageView.setImageBitmap(bitmap);

        TextView tv = (TextView) findViewById(R.id.imagepath);
        tv.setText(picturePath);

        Button share = (Button) findViewById(R.id.btnShare);

        share.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("image/*");
                intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(picturePath));
                startActivity(Intent.createChooser(intent, "Share"));

            }
        });
    }
}
4

1 回答 1

0

放入 onClickListener

                imageView.setDrawingCacheEnabled(true);
                Bitmap bitmap = imageView.getDrawingCache();
                File root = Environment.getExternalStorageDirectory();
                File cachePath = new File(root.getAbsolutePath() + "/DCIM/Camera/image.jpg");
                try {
                    cachePath.createNewFile();
                    FileOutputStream ostream = new FileOutputStream(cachePath);
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, ostream);
                    ostream.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }


                Intent share = new Intent(Intent.ACTION_SEND);
                share.setType("image/*");
                share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(cachePath));
                startActivity(Intent.createChooser(share,"Share via"));
于 2016-09-23T13:43:00.647 回答