分享图像使用意图在android系统
我想分享图片和文字到另一个应用程序,但我发现,当我使用此代码,请帮助文件格式不支持其他应用程序...分享图像使用意图在android系统
Uri picUri = Uri.parse("http://www.planwallpaper.com/static/images/image-slider-2.jpg");
Intent shareIntent = new Intent();
shareIntent.setAction(android.content.Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Hi There...");
shareIntent.putExtra(android.content.Intent.EXTRA_STREAM, picUri);
shareIntent.setType("*/*");
startActivity(Intent.createChooser(shareIntent, "Share Image...."));
试试这个
private class myTask extends AsyncTask<Void, Void, Bitmap> {
protected Bitmap doInBackground(Void... params) {
Bitmap myBitmap=null;
try {
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
myBitmap = BitmapFactory.decodeStream(input);
} catch (IOException e) {
// Log exception
}
return myBitmap;
}
@Override
protected void onPostExecute(Bitmap result) {
//do stuff
}
}
Bitmap returned_bitmap = new myTask().execute().get()
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "download this image");
String bitmapPath = Images.Media.insertImage(getContentResolver(), returned_bitmap,"title", null);
Uri bitmapUri = Uri.parse(bitmapPath);
intent.putExtra(Intent.EXTRA_STREAM, bitmapUri);
intent.setType("image/*");
startActivity(Intent.createChooser(intent, "Share image via..."));
当我使用您发送的第一个代码时,我收到文件未找到异常.... –
java.io.FileNotFoundException:http: /www.planwallpaper.com/static/images/image-slider-2.jpg:打开失败:ENOENT(没有这样的文件或目录) –
你想发送图像url或图像到其他应用程序 –
The documentation for EXTRA_STREAM
表示Uri
需要有一个content
方案。至少在Android 6.0和更旧版本上,file
通常也起作用。几乎没有应用程序会期望http
URL。
为什么不分享URI作为一个字符串? –
我试过它不起作用@Nilesh发布的波纹管代码作品 –