我试图在缓存目录中共享图像文件,我有完整的路径,但无法在附件中发送文件,代码是
File shareImage=Utils.getBitmapFile();
Log.d("Activity", "get final path in result"+shareImage.getAbsolutePath());
/*MimeTypeMap mime = MimeTypeMap.getSingleton();
String ext=shareImage.getName().substring(shareImage.getName().lastIndexOf(".")+1);
String type = mime.getMimeTypeFromExtension(ext);
shareIntent.setType(type);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");
Uri shareImageUri = Uri.fromFile(shareImage);
Uri shareImageUri = Uri.fromParts("content", shareImage.getAbsolutePath(), null);//("content://"+shareImage.getAbsolutePath());
*/
Uri shareImageUri = Uri.fromFile(shareImage);
Log.d("Result ","uri is "+shareImageUri.toString());
shareIntent.putExtra(Intent.EXTRA_STREAM, shareImageUri);
startActivity(Intent.createChooser(shareIntent, "Share Results"));
Run Code Online (Sandbox Code Playgroud)
上面注释的代码不起作用
发送邮件显示附件,但没有收到结束没有附件,Facebook共享也显示邮件中没有图像
这是什么原因?
我已经看到以下SO链接如何使用共享图像使用共享意图共享图像在Android和许多其他人,他们都没有能够解决这个问题
PS;
1.目的是将屏幕截图保存在缓存目录中并从那里在线共享
2.我确实有文件,我可以通过DDMS从设备中取出它并在系统上查看.
我想在图像视图中共享图像.但我不想保存到SD卡.但是,当我使用Intent分享我使用过的代码时
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
share.putExtra(Intent.EXTRA_STREAM,Uri.parse(path));
startActivity(Intent.createChooser(share, "Share Image"));
Run Code Online (Sandbox Code Playgroud)
这里路径指定了SD卡中图像的位置
但我不想保存图像...有可能..
也许这是一个简单的问题:我想通过网络分享一个位图,用默认共享"意图"分享到twitter/facebook/etc.
我找到的代码
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("image/jpeg");
sendIntent.putExtra(Intent.EXTRA_STREAM, "IDONTKNOW");
sendIntent.putExtra(Intent.EXTRA_TEXT,
"See my captured picture - wow :)");
startActivity(Intent.createChooser(sendIntent, "share"));
Run Code Online (Sandbox Code Playgroud)
需要在位图"IDONTKNOW"处填充位图.(this.bitmap)
如果不将位图保存到内部sd,我发现无法处理此问题.
问候
我已经使用了这段代码,并且可以通过我的Android应用程序成功地将图像(来自我手机的图库)与文本分享到谷歌+.
但是,当我尝试从我的应用内容提供商发布图片时,图片会显示在我的Google +页面上,就像这样......

...即使在谷歌+应用预览屏幕上显示的预期图像很好.
我用来分享的代码是:
String message = "My message";
Uri localImageUri = ContentUris.withAppendedId(DbContentProvider.CONTENT_URI_PRODUCTS, mProductId;
PlusShare.Builder builder = new PlusShare.Builder(getActivity());
builder.setText(message);
builder.addStream(localImageUri);
builder.setType("image/jpeg");
Intent shareIntent = builder.getIntent();
startActivityForResult(shareIntent, RC_GOOGLE_PLUS);
Run Code Online (Sandbox Code Playgroud)
...而且,就像我说的,如果localImageUri值是针对我手机图库中的资源,则图像会成功显示在最终的Google +页面上 - 如果我localImageUri从应用程序自己的内容提供商设置为uri,则显示上面的占位符图像.
所以我认为我的内容提供商一定存在问题,我的清单中将其定义为:
<provider
android:name=".DbContentProvider"
android:authorities="com.example.provider"
android:exported="true"
android:grantUriPermissions="true" />
Run Code Online (Sandbox Code Playgroud)
那么,我的清单中是否会遗漏一些东西 - 甚至是我的searchable.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"
android:hint="@string/search_hint"
android:searchSuggestAuthority="com.example.provider"
android:searchSuggestIntentAction="android.intent.action.VIEW"
android:searchSuggestIntentData="content://com.example.provider/suggest"
android:searchSuggestThreshold="3"
android:includeInGlobalSearch="true"
android:searchSettingsDescription="@string/search_settings_description"
android:queryAfterZeroResults="true"
android:voiceSearchMode="showVoiceSearchButton" >
</searchable>
Run Code Online (Sandbox Code Playgroud)
如果没有,那么问题是什么呢?
更新(遵循CommonsWare的评论)
异常确实是由Google+信息库抛出,因为也做在查询_data栏(其存在),借助Google+ API,也一直在寻找一个不存在的列-即datetaken,date_added,date_modified.
所以我已经将这些列添加到我的数据库表中 …
我有一个应用程序,它截取屏幕截图,并与共享意图分享.每次用户想要简单地共享图像时,不是保存多个图像.以下是我用于保存到SD的图像的代码
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/png");
dir = "file://" + Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "Folder/" + location;
share.putExtra(Intent.EXTRA_STREAM, Uri.parse(dir));
startActivity(Intent.createChooser(share, "Share Image"));
Run Code Online (Sandbox Code Playgroud)
但是,我无法弄清楚如何简单地保存位图,如...
share.putExtra(Intent.EXTRA_STREAM, theBitmap);
Run Code Online (Sandbox Code Playgroud)
有没有办法在不保存图像的情况下执行此操作?
谢谢
我正在尝试使用BitmapFactory.decodefile()来创建相机照片的缩小版本,并将其设置为我的framelayout中的imageview.遵循Android开发人员的以下说明:https: //developer.android.com/training/camera/photobasics.html 在这些说明中,文件创建并存储在fileprovider中,该文件提供程序包含一些以xml格式化的元数据文件.不知何故,BitmapFactory.decodefile()似乎无法访问此文件,该文件存储内容uri驻留在fileprovider中的图片.fileprovider是在androidmanifest文件中创建的,如下所示:
<provider
android:authorities="mypackagename.fileprovider"
android:name="android.support.v4.content.FileProvider"
android:exported="false" android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" >
</meta-data>
</provider>
Run Code Online (Sandbox Code Playgroud)
file_paths xml文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="my_images" path="Android/data/mypackagename/files/Pictures/" />
</paths>
Run Code Online (Sandbox Code Playgroud)
通过以下方法生成图片所在的文件名:
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(imageFileName,".jpg",storageDir);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = image.getAbsolutePath();
Log.d("absolute",""+image.getAbsolutePath());
return image;
} …Run Code Online (Sandbox Code Playgroud) android uri android-intent bitmapfactory android-fileprovider