【发布时间】:2016-09-14 04:23:59
【问题描述】:
我正在尝试共享图像,它似乎仅在安装了 SD 卡或手机没有 SD 卡插槽时才有效。但是当我卸载 SD 卡时,它不会共享,它给了我两个错误。
致命异常:main java.lang.NullPointerException:uriString
无法插入图像 java.io.FileNotFoundException:没有这样的文件或目录
由于某种原因,它还保存了正在共享的图像,似乎无法弄清楚原因。
private Button button;
public void onCreate {
init();
setupView();
}
public void setupView(){
button.setOnClickListener(this);
}
public void init() {
button = (Button) findViewById(R.id.button);
}
@Override
public void onClick(View v) {
int id = v.getId();
switch (id) {
case R.id.button: {
startShare();
break;
}
public void startShare() {
Bitmap b =BitmapFactory.decodeResource(getResources(),R.drawable.m1);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(getContentResolver(),
b, "Title", null);
Uri imageUri = Uri.parse(path);
share.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(share, "Share"));
}
【问题讨论】:
-
不,没有帮助,还是谢谢。
-
你在这里得到
ExceptionBitmap b =BitmapFactory.decodeResource(getResources(),R.drawable.m1);FileNotFoundException。
标签: java android android-intent share mms