我在该应用程序中有图像厨房应用程序我将所有图像放入drawable-hdpi文件夹中.我在我的活动中调用了这样的图像:
private Integer[] imageIDs = {
R.drawable.wall1, R.drawable.wall2,
R.drawable.wall3, R.drawable.wall4,
R.drawable.wall5, R.drawable.wall6,
R.drawable.wall7, R.drawable.wall8,
R.drawable.wall9, R.drawable.wall10
};
Run Code Online (Sandbox Code Playgroud)
所以现在我想知道我如何使用共享Intent我分享这些图像我推出的共享代码如下:
Button shareButton = (Button) findViewById(R.id.share_button);
shareButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(Images.Media.EXTERNAL_CONTENT_URI + "/" + imageIDs);
sharingIntent.setType("image/jpeg");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
}
});
Run Code Online (Sandbox Code Playgroud)
当我点击分享按钮时我也有共享按钮分享框正在打开但当我克服任何服务时,大多数崩溃或一些服务说:无法打开图像所以我怎么能解决这个问题或者是否有任何其他格式代码来共享图像????
编辑:
我尝试使用下面的代码.但它不起作用.
Button shareButton = (Button) findViewById(R.id.share_button);
shareButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse("android.resource://com.android.test/*");
try { …Run Code Online (Sandbox Code Playgroud) 我尝试使用共享意图从我的应用程序导出位图,而不保存文件的临时位置.我发现的所有例子都是两步1)保存到SD卡并为该文件创建Uri 2)用这个Uri启动意图
是否可以在不需要WRITE_EXTERNAL_STORAGE权限的情况下进行保存,保存文件[并在之后将其删除]?如何在没有ExternalStorage的情况下寻址设备?
我在我的应用程序中创建图像,并希望共享这些社交网络(Facebook),邮件应用程序(Gmail)和其他可以"接收"图像的应用程序.
问题的根源(我认为)是我不想使用外部存储作为我的图像的基础.我想要使用我的数据文件夹或我的缓存文件夹,因为这些都不需要任何访问权限.
我用来将我的图像写入文件的代码(我指定了MODE_WORLD_READABLE以便其他应用程序可以读取它们):
FileOutputStream fos = null;
try {
fos = context.openFileOutput("image.jpg", Context.MODE_WORLD_READABLE);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
} finally {
if (fos != null)
fos.close();
}
Run Code Online (Sandbox Code Playgroud)
这是我分享图像的代码:
File internalFile = context.getFileStreamPath("image.jpg");
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(internalFile));
intent.setType("image/jpeg");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(Intent.createChooser(intent, "share"));
Run Code Online (Sandbox Code Playgroud)
这个解决方案非常简单,适用于像facebook这样的应用程序,但不适用于例如gmail的应用程序:
file:// attachment paths must point to file:///mnt/sdcard
Run Code Online (Sandbox Code Playgroud)
有一些"黑客"(见下文)让它与gmail一起工作,但是我让自己问自己是否有更好的方法来分享没有黑客的图像,我忽略了一些东西.所以,对于问题: