我是 android studio 的初学者,我认为这会很容易,但我也没有明白
如何从链接共享图像,即,无需下载图像,只需在社交媒体(例如应用程序)上共享。我可以下载图像,然后共享,然后删除该图像,但我不想这样做。我正在使用 glide 库在图像视图中加载图像,然后当用户单击按钮时,它只会共享图像视图中显示的图像以及我拥有的链接,然后返回应用程序。
我正在使用 Glide 库来加载图像。
任何帮助将不胜感激。
提前致谢。
首先,您需要在 glide 中加载图像(因为您正在使用 glide ),然后您可以将其共享到任何地方,但图像将保存到存储中
从 glide 加载图像的代码(图像正在保存到存储中,您可以稍后删除它)
Glide.with(getApplicationContext())
.load(imagelink) \\link of your image file (url)
.asBitmap().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE)
.into(new SimpleTarget<Bitmap>(250, 250) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "Hey view/download this image");
String path = MediaStore.Images.Media.insertImage(getContentResolver(), resource, "", null);
Uri screenshotUri = Uri.parse(path);
intent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
intent.setType("image/*");
startActivity(Intent.createChooser(intent, "Share image via..."));
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
Toast.makeText(getApplicationContext(), "Something went wrong", Toast.LENGTH_SHORT).show();
super.onLoadFailed(e, errorDrawable);
}
@Override
public void onLoadStarted(Drawable placeholder) {
Toast.makeText(getApplicationContext(), "Starting", Toast.LENGTH_SHORT).show();
super.onLoadStarted(placeholder);
}
});
如果需要,可以通过添加更多代码从存储中删除该图像
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)