我正在尝试分享我的 Android 应用程序中的图像。我正在尝试将其作为电子邮件附件以及 WhatsApp 上的照片发送。
代码是:
String imageUrl = Path to image (eg. sdcard/pictures/image1.jpg);
shareImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Uri uriToImage= Uri.parse(imageUrl);
Log.d("Image", ""+uriToImage);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share image:"));
}
});
Run Code Online (Sandbox Code Playgroud)
发生的事情是:
Photo couldn't be found此处给出了我为此遵循的教程。本教程的部分send binary content是我已经实现的部分。
我尝试的另一件事是将图像设置为 anImageView并查看它是否显示。图像显示正确。此外,日志消息打印图像的正确路径。
我还阅读并尝试了以下问题的答案:问题1和问题2,但无济于事。
我哪里错了?
是否可以共享特定应用程序的资源,例如位于res文件夹下的位图图像/图标与另一个应用程序?这是在接受采访时被问到的,我没有任何线索.有没有具体的理由说明为什么这种共享不可能发生,或者如果可能的话,怎么样?
我需要从我的 RecyclerAdapter 共享一个图像,因为该图像最初并不存在,即使用适配器在 Activity 中加载。如何将位图分享到社交媒体?每次我在我的应用程序中单击共享时,它都会显示“没有应用程序可以执行此操作”。
feedItemView.setFeedSocialShareClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Share to Social Media
ImageView imageView = (ImageView) feedItemView.findViewById(R.id.image);
Drawable mDrawable = imageView.getDrawable();
Bitmap mBitmap = ((BitmapDrawable)mDrawable).getBitmap();
String path = MediaStore.Images.Media.insertImage(context.getContentResolver(),
mBitmap, "Design", null);
Uri uri = Uri.parse(path);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image");
share.putExtra(Intent.EXTRA_STREAM, uri);
share.putExtra(Intent.EXTRA_TEXT, "I found something cool!");
context.startActivity(Intent.createChooser(share, "Share Your Design!"));
}
});
Run Code Online (Sandbox Code Playgroud) java android android-contentresolver android-sharing android-recyclerview
我正在尝试创建文本文件并共享它(通过蓝牙,电子邮件..)
File file = null;
try {
file = createFile2(json);
} catch (IOException e) {
e.printStackTrace();
}
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, file);
shareIntent.setType(getString(R.string.share_contact_type_intent));
Run Code Online (Sandbox Code Playgroud)
这是createFile2()的乐趣:
public File createFile2(String text) throws IOException {
File file = new
File(getFilesDir() + File.separator + "MyFile.txt");
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));
bufferedWriter.write(text);
bufferedWriter.close();
return file;
}
Run Code Online (Sandbox Code Playgroud)
logcat的:
Bundle? Key android.intent.extra.STREAM expected Parcelable but value was a java.io.File. The default value <null> was returned.
Bundle? Attempt to cast generated …Run Code Online (Sandbox Code Playgroud) 我想将图像从我的应用程序共享到whatsapp,但是在whatsapp上成功共享之后,我想在应用程序中调用Web服务,请问有人可以帮助我完成此任务...
我环顾了网上,但尚未找到适合我特定需求的解决方案。我正在寻找一种使用共享意图共享信息的方法,该意图提供可点击的链接,例如:
查看此新闻文章
我已经在我的android应用中成功设置了一个共享意图,如下所示:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject Text");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Check out this news article" + "\n\n" + getResources().getText(R.string.shared_via));
shareIntent.setType("text/plain");
startActivity(Intent.createChooser(shareIntent, "Share this article with..."));
Run Code Online (Sandbox Code Playgroud)
我的字符串资源如下所示:
<string name="shared_via">via <a ref="http://google.com">Jimmy's News App</a></string>
Run Code Online (Sandbox Code Playgroud)
但是,共享功能可以在电子邮件,Twitter等中共享时发挥应有的作用。链接将被忽略,并且推文仅显示如下纯文本:

我尝试使用MIME类型,但还是没有雪茄。共享时是否有可点击的“吉米新闻应用程序”?对于任何帮助和提示,我都非常感激。
提前致谢!
目前我正在使用以下代码来共享文本:
Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_TEXT, "This is tesing");
startActivity(Intent.createChooser(i, "Share via"));
Run Code Online (Sandbox Code Playgroud)
从此我可以在任何社交媒体平台上分享文本.
但我想与此分享图像,我的图像是二进制形式.
InputStream input = new java.net.URL(
product.getString("url")).openStream();
// Decode Bitmap
bitmap = BitmapFactory.decodeStream(input);
Run Code Online (Sandbox Code Playgroud)
所以图像共享我写了下面的代码:
i.putExtra(android.content.Intent.EXTRA_TEXT, bitmap);
Run Code Online (Sandbox Code Playgroud)
但它没有用.它分享如下文字: - android.graphics.Bitmap@43394c40
那么我怎样才能与此分享形象呢?
我正在我的应用程序中添加共享功能,除了共享到 Snapchat 之外,一切正常。当我发送“发送”意图时,Snapchat 只会打开它自己的相机预览,而我的照片丢失了。我尝试了不同的东西,但没有任何帮助。此外,当我通过标准的 Android 共享屏幕共享时,Snapchat 成功打开了它。所以这是我的代码:
var tempFile = File(filePath)
val sharingIntent = Intent(Intent.ACTION_SEND)
sharingIntent.type = "image/jpg"
sharingIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
val image = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, tempFile)
sharingIntent.putExtra(Intent.EXTRA_STREAM, image)
sharingIntent.`package` = "com.snapchat.android"
return sharingIntent
Run Code Online (Sandbox Code Playgroud)
我使用 FileProvider :
<provider
android:name="android.support.v4.content.FileProvider"
android:grantUriPermissions="true"
android:exported="false"
android:authorities="${applicationId}">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_path"/>
</provider>
Run Code Online (Sandbox Code Playgroud)
还有这样的路径:
<paths>
<cache-path name="cache" path="/" />
Run Code Online (Sandbox Code Playgroud)
你能帮我弄清楚是什么问题吗?感谢所有的答案!
尝试共享图像文件时,我不断收到此错误:
java.lang.RuntimeException:android.os.TransactionTooLargeException:数据包大小1085992字节
我假设一个解决方案是将图像压缩得更多,这会减小尺寸.这是完成这项工作的功能:
public static File saveBitmaptoFile(Bitmap bitmap, File pictureFile) {
FileOutputStream out = null;
try {
out = new FileOutputStream(pictureFile);
// on the next line I'm trying compress the heck out of image.
bitmap.compress(Bitmap.CompressFormat.JPEG, 1, out);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return pictureFile;
}
Run Code Online (Sandbox Code Playgroud)
这是共享功能:
private void shareToInstagram() {
String type = "image/png";
Intent share = new Intent(Intent.ACTION_SEND); …Run Code Online (Sandbox Code Playgroud)