我在我的活动中显示图像,并希望通过意图分享。 我收到错误:不支持图像格式,无论它是jpg还是png。
我的代码中可能存在错误:
public class StartActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Intent myIntent = getIntent();
int image = myIntent.getExtras().getInt("image");
ImageView imagefull = (ImageView)findViewById(R.id.imageView1);
imagefull.setImageResource(image);
Button share = (Button) findViewById (R.id.buttonshare);
share.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
Uri uri = Uri.fromFile(new File(getFilesDir(), "facebook.png"));
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(share, "Share Image!"));
} });
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
答案 0 :(得分:0)
尝试使用share.setType("image/png");
表示PNG,share.setType("image/jpg");
表示JPEG。
答案 1 :(得分:0)
试试这个: -
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.setType("image/*");
//set your message
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, msgText);
String imagePath = Environment.getExternalStorageDirectory() + File.separator + "image_name.jpg";
File imageFileToShare = new File(imagePath);
Uri uri = Uri.fromFile(imageFileToShare);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
Uri uri = Uri.fromFile(imageFileToShare);
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);