【问题标题】:Share image taking from Camera分享从相机拍摄的图像
【发布时间】:2017-10-07 15:43:14
【问题描述】:

我正在开发一个应用程序,它可以用相机拍照并允许用户分享。但是共享意图不起作用。我已经检查过,但没有人在我的设备上工作。我在 Android 6.0 marshmallow 平板电脑上运行该应用程序。

这是我的代码

public class SharePic extends Activity {

static final int REQUEST_IMAGE_CAPTURE = 1;
ImageView picView;
Button shareBtn;
Bitmap imageBitmap;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_share_pic);
    picView = (ImageView) findViewById(R.id.picView);
    shareBtn = (Button) findViewById(R.id.shareBtn);

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);


    }
    }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
        Bundle extras = data.getExtras();
        imageBitmap = (Bitmap) extras.get("data");
        picView.setImageBitmap(imageBitmap);
    }
}


public void share(View view){
    String bitmapPath = MediaStore.Images.Media.insertImage(getContentResolver(), imageBitmap,"title", null);
    Uri bitmapUri = Uri.parse(bitmapPath);
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("image/png");
    intent.putExtra(Intent.EXTRA_STREAM, bitmapUri);
    startActivity(Intent.createChooser(intent , "Share"));
}
}

有什么帮助吗?

【问题讨论】:

    标签: java android android-intent android-camera-intent


    【解决方案1】:

    那么,何时调用共享按钮。 我猜您可能必须在单击共享按钮时设置事件侦听器setOnClickListener,以防您尚未在 XML 中设置它

    shareBtn.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    share(v);
                }
            });
    

    【讨论】:

      猜你喜欢
      • 2011-07-15
      • 2018-09-15
      • 1970-01-01
      • 2013-11-10
      • 2016-02-13
      • 1970-01-01
      • 1970-01-01
      • 2017-09-20
      • 1970-01-01
      相关资源
      最近更新 更多