使用Intent共享文本、图片、视频等资源
来源:互联网 发布:淘宝助理批量改价格 编辑:程序博客网 时间:2024/05/09 05:08
Very often, you might want to enable the ability for users to share some content (either text, link or an image) from your Android app. Users can share the content using email, twitter, Facebook, sms or through numerous other ways.
The users might already have installed some custom apps for each one of the above service. So instead of coding all these again, it would be really nice (for both your users as well as for you as a developer) if you can invoke any one of these apps, where users want to share content from your app.
Sharing text
Android provides a built-in Intent called ACTION_SEND for this purpose. Using it in your app is very easy. All you have to do is to use the following couple of lines.
Intent sharingIntent = new Intent(Intent.ACTION_SEND);sharingIntent.setType("text/html");sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml("<p>This is the text that will be shared.</p>"));startActivity(Intent.createChooser(sharingIntent,"Share using"));
In my phone, it invokes the following dialog box listing the apps that have registered to get notification for this intent.
Sharing binary objects (Images, videos etc.)
In addition to supporting text, this intent also supports sharing images or any binary content. All you have to do is to set the appropriate mime type and then pass the binary data by calling the putExtra method.
Intent sharingIntent = new Intent(Intent.ACTION_SEND);Uri screenshotUri = Uri.parse(path);
sharingIntent.setType("image/png");sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);startActivity(Intent.createChooser(sharingIntent, "Share image using"));
Registering for the Intent
If you want your app to be listed when this Intent is called, then you have to add an intent filter in your manifest.xml file
<intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="image/*" /></intent-filter>
android:mimeType
specifies the mime type which you are interested in listening.
Happy sharing
- 使用Intent共享文本、图片、视频等资源
- WP7中非文本资源(图片、音频等)的本地化
- 直接访问tomcat下静态资源:文本、图片等
- 本地资源图片和视频的使用
- 图片等资源的使用Properties.Resources
- 使用变量引用图片等资源
- ueditor使用_3_图片视频等上传
- android通过Intent调用手机图片,音频,视频录音拍照等代码
- android通过Intent调用手机图片,音频,视频录音拍照等代码
- windows Mobile 开发中使用嵌入的图片等资源
- 使用资源文件中资源(从资源文件中获取文字图片等)
- Unity3d外部加载音频,视频,图片等资源 及根据路径获取制定格式的文件
- 富文本使用等
- android通过intent选取视频、图片、音频
- 获取QQ图片等资源
- Android使用Intent一键分享图片文字到腾讯、新浪、开心、微信等
- android 使用Intent.ACTION_SEND分享图片和文字内容(新浪微博,短信等)
- Android使用Intent一键分享图片文字到腾讯、新浪、开心、微信等
- ASIC:万兆路由的基石
- uboot 中内存测试,内存检测方法
- Android 个人感觉很棒的一个背景,可以作为标题栏的背景
- 推荐3岁以下宝宝的爸爸妈妈阅读
- CodeSmith的模板被exclude了,要恢复回来的一些技巧(转)
- 使用Intent共享文本、图片、视频等资源
- 只考虑节省空间造成的功能错误
- 切换域账号访问
- union(C/C++)使用的一些总结
- Log4j使用实例
- GlusterFS文档翻译 - Understanding AFR Translator 中文化
- JavaScript中判断对象类型的种种方法
- FTP 命令详解
- 每天进步一点点-->WIN32_FIND_DATA