我如何在 Android 中分享文字和图片
How can i share text and image in Android
我想分享我的应用程序的内容(文本和图像),对于这个问题,我写了下面的代码:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("*/*");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(content) + "" +"\n\n" + "download us app from this link" + "\n\n" +"https://play.google.com/app/com.example.example");
startActivity(Intent.createChooser(sharingIntent, "select app ..."));
但是在这段代码中,我只能分享文字,不能分享图片!我想分享文字和图片。
为了显示文本和图像,我使用 Webview
。我在 webview
.
中将图像显示为文本
如何分享文字和图片?
见下方代码,
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/png");
intent.putExtra(Intent.EXTRA_TEXT,"http://lorempixel.com/400/200/sports/1/");//your Image Url
startActivity(Intent.createChooser(intent, "Share Image"));
将图像的 URI 添加到捆绑包中(例如 http://some.server.com/your_image.png),这将允许在从捆绑包中提取数据时找到并使用相同的图像。
以下代码可用于与其他应用共享文本和图像。
String imageToShare = "http://s1.dmcdn.net/hxdt6/x720-qef.jpg"; //Image You wants to share
String title = "Title to share"; //Title you wants to share
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, title);
shareIntent.setType("*/*");
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_TEXT, imageToShare);
startActivity(Intent.createChooser(shareIntent, "Select App to Share Text and Image"));
我想分享我的应用程序的内容(文本和图像),对于这个问题,我写了下面的代码:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("*/*");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(content) + "" +"\n\n" + "download us app from this link" + "\n\n" +"https://play.google.com/app/com.example.example");
startActivity(Intent.createChooser(sharingIntent, "select app ..."));
但是在这段代码中,我只能分享文字,不能分享图片!我想分享文字和图片。
为了显示文本和图像,我使用 Webview
。我在 webview
.
如何分享文字和图片?
见下方代码,
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/png");
intent.putExtra(Intent.EXTRA_TEXT,"http://lorempixel.com/400/200/sports/1/");//your Image Url
startActivity(Intent.createChooser(intent, "Share Image"));
将图像的 URI 添加到捆绑包中(例如 http://some.server.com/your_image.png),这将允许在从捆绑包中提取数据时找到并使用相同的图像。
以下代码可用于与其他应用共享文本和图像。
String imageToShare = "http://s1.dmcdn.net/hxdt6/x720-qef.jpg"; //Image You wants to share
String title = "Title to share"; //Title you wants to share
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, title);
shareIntent.setType("*/*");
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_TEXT, imageToShare);
startActivity(Intent.createChooser(shareIntent, "Select App to Share Text and Image"));