我正在使用此代码共享文件:
Uri fileUri = Uri.fromFile(new File(filePath));
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("audio/mp3");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "subject");
shareIntent.putExtra(Intent.EXTRA_TEXT, "body");
shareIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
startActivity(Intent.createChooser(shareIntent, "Share"));
Run Code Online (Sandbox Code Playgroud)
文件名是:"a123456789cd.mp3".我无法更改实际的文件名,因此我只需要在附件中将其更改为有意义的内容,例如:"myRecording.mp3".那可能吗 ?
谢谢你的帮助
我正在使用带有此代码的android本机共享:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "I like to share with you some stuff.");
intent.putExtra(Intent.EXTRA_SUBJECT, "I like to share with you.");
intent.setType(CONTENT_TYPE_TEXT);
startActivity(Intent.createChooser(intent, "Share");
Run Code Online (Sandbox Code Playgroud)
当我使用电子邮件作为分享渠道时,我得到了我想要的:
Subject: I like to share with you.
Text: I like to share with you some stuff.
Run Code Online (Sandbox Code Playgroud)
当我使用 WhatsApp 作为分享渠道时,我得到以下文本:
I like to share with you.
I like to share with you some stuff.
Run Code Online (Sandbox Code Playgroud)
与 Whatsapp 分享时我期望什么:
I like to share with you some stuff.
Run Code Online (Sandbox Code Playgroud)
如果共享频道基本上不支持主题,是否有任何选项/标志指示共享频道来抑制主题。
例如,电子邮件支持主题 -> 使用额外提供的意图。WhatsApp 不支持主题 -> 不要额外使用提供的意图。
似乎只有在其他应用程序手动询问READ_EXTERNAL_STORAGE权限时才能将数据共享到Android M上的其他应用程序,我想知道是否有人知道解决此问题的方法,而无需手动打开我可以共享的所有应用程序并选择存储权限.
例如,我有以下Intent来共享一些数据:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Some Image Subject");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(someFile));
startActivity(Intent.createChooser(shareIntent, "Share via..."));
Run Code Online (Sandbox Code Playgroud)
假设someFile存在且我已经按照http://developer.android.com/training/permissions/requesting.html上建议的运行时权限模型进行操作,并且用户同意允许我的权限,因此文件实际上是在系统.
有没有办法告诉我正在分享的应用程序,我已经将此权限授予我的用户,请您代表我授予此权限?
这不起作用:
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Run Code Online (Sandbox Code Playgroud)
根据文件:
int FLAG_GRANT_READ_URI_PERMISSION
如果设置,则此Intent的接收者将被授予对Intent数据中的URI和其ClipData中指定的任何URI执行读取操作的权限.
更有趣的是,如果设置此标记并且我与Gmail共享,则不会检测到该标记,并且Google不会提示请求权限,而是仅捕获异常并且不附加我的文件.
任何帮助,将不胜感激.
我引用了示例应用程序代码(https://github.com/googlesamples/android-DirectShare),然后将ChooserTargetService添加到了我的应用程序中
public class ShareChooserTargetService extends ChooserTargetService {
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName,
IntentFilter matchedFilter) {
Log.d("ShareChooserTargetService", "onGetChooserTargets: ");
ComponentName componentName = new ComponentName(getPackageName(),
ShareActivity.class.getCanonicalName());
ArrayList<ChooserTarget> targets = new ArrayList<>();
for (User user : Users.getAll()) {
Bundle extras = new Bundle();
extras.putInt("user_id", user.id);
targets.add(new ChooserTarget(
user.name,
Icon.createWithResource(this, R.mipmap.ic_user),
componentName,
extras));
}
return targets;
}
Run Code Online (Sandbox Code Playgroud)
在清单文件中,我添加了以下几行:
<activity
android:name=".ui.ShareActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
<meta-data
android:name="android.service.chooser.chooser_target_service"
android:value=".ShareChooserTargetService" />
</activity>
<service
android:name=".ShareChooserTargetService" …Run Code Online (Sandbox Code Playgroud) 我尝试了很多方法,但我不能这样做.
我有一个*.txt文件.我希望通过它分享Bluetooth , wifi , email and ....
当我使用此代码时,我无法共享该文件:
File file = new File(Environment.getExternalStorageDirectory(), "Email-Ghap/Emails.txt");
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("*/txt");
sharingIntent.putExtra(Intent.EXTRA_STREAM, file);
startActivity(Intent.createChooser(sharingIntent, "share file with"));
Run Code Online (Sandbox Code Playgroud)
我完全想要这样:当用户点击共享按钮并选择一个电子邮件发件人(如Gmail)进行共享时.该文件必须附加新文件的文件...
我找到了这个链接/sf/answers/1122537461/
但它共享txt文件内容.我想共享文件而不是txt文件的内容
在 Android 上,我尝试像这样共享图像+文本:
Uri imageUri = Uri.parse("android.resource://" + getPackageName()
+ "/drawable/" + "ic_launcher");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello");
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "send"));
Run Code Online (Sandbox Code Playgroud)
这个工作正常Whatsapp(例如),但viber它只显示图像并跳过文本:(在 Instagram 上,情况完全相反,发送文本但不发送图像......
我能怎么做 ?
我是 android studio 的初学者,我认为这很容易,但我也不明白
如何从链接共享图像,即,无需下载图像,只需在社交媒体上共享,例如 whats 应用程序。我可以下载图像,然后共享,然后将其删除,但我不想这样做。我正在使用 glide 库在图像视图中加载图像,然后当用户单击一个按钮时,它只会共享其在图像视图中显示的图像以及我拥有的链接,然后返回到应用程序。
我正在使用 Glide 库来加载图像。
任何帮助将不胜感激。
提前致谢。
我已经阅读了关于这个论点的所有答案,但我总是收到收到我的照片的应用程序的错误.
不仅如此方式工作对我来说,所有的应用程序,是这样的(它的工作原理,因为SD卡的文件都是公开的所有应用程序):
final File tmpFile = new File(context.getExternalCacheDir(), "exported.jpg");
Uri tmpFileUri = Uri.fromFile(tmpFile);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setDataAndType(tmpFileUri, "image/jpeg");
shareIntent.putExtra(Intent.EXTRA_STREAM, tmpFileUri);
context.startActivity(Intent.createChooser(shareIntent, context.getString(R.string.share_image)));
Run Code Online (Sandbox Code Playgroud)
现在,我坚持如何共享位于私人文件夹中的文件.我使用了google文档提供的代码:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.test.myapp.fileprovider"
android:exported="false"
android:grantUriPermissions="true" >
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>
...
...
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="internal_files" path="/"/>
<cache-path name="internal_cache" path="/" />
</paths>
Run Code Online (Sandbox Code Playgroud)
这是使用该文件共享文件的代码,FileProvider但不适用于任何应用程序,除非是最新的:
final File tmpFile = new File(context.getCacheDir(), "exported.jpg");
Uri tmpFileUri = FileProvider.getUriForFile(context, context.getPackageName() + ".fileprovider", tmpFile);
//Remove the uri permission because we overwrite …Run Code Online (Sandbox Code Playgroud) 我想共享一个文本,点击用户将通过android共享意图导航到一个URL.
例如:
"访问谷歌了解更多信息."
在上面的文字中,点击谷歌后,用户将被重定向到google.com.我需要实现这样的事情,而不是向用户显示完整的URL.我试过的是使它与href的html链接不起作用.
那么,我该如何实现呢?
我正在尝试使用Intent进行共享.它适用于单个图像或使用Intent.ACTION_SEND时.
但是,当我使用Intent.ACTION_SEND_MULTIPLE它似乎不适用于Facebook,例如我使用下面的代码.
ArrayList<Uri> files = new ArrayList<Uri>();
File a = new File(FileUtil.getDefaultMediaFolderPath(), "a.jpeg");
File b = new File(FileUtil.getDefaultMediaFolderPath(), "b.jpeg");
files.add(Uri.fromFile(a));
files.add(Uri.fromFile(b));
if (a.exists()) {
if (b.exists()) {
System.out.println("Both present.");
}
}
Intent shareIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
shareIntent.setType("*/*");
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
startActivity(Intent.createChooser(shareIntent,"share via."));
Run Code Online (Sandbox Code Playgroud)
以上代码适用于Gmail,并附带Gmail图片.但是对于facebook,它似乎不起作用,图像也没有附加.
我尝试了不同的组合,但似乎没有任何效果.虽然当我尝试从设备默认图库共享多个图像时,它运行良好并附加Facebook中的所有图像.
请帮我 !!
android ×10
android-sharing ×10
android-file ×1
email ×1
facebook ×1
java ×1
viber ×1
whatsapp ×1