使自己的应用出现在分享列表
来源:互联网 发布:航盛导航端口 编辑:程序博客网 时间:2024/06/11 21:16
实现分享功能
上面说的都是怎么调用分享功能,以下就开始写怎么实现分享功能,让我们的应用也出现在分享列表中。前面也说了分享功能是使用隐式调用Activtiy实现的,Activity需要声明 <intent-filter>
。
声明intent-filter
- <activity
- android:name="com.example.sharedemo.ShareActivity"
- android:label="@string/app_name" >
- <intent-filter>
- <action android:name="android.intent.action.SEND" />
- <category android:name="android.intent.category.DEFAULT" />
- <data android:mimeType="image/*" />
- </intent-filter>
- <intent-filter>
- <action android:name="android.intent.action.SEND" />
- <category android:name="android.intent.category.DEFAULT" />
- <data android:mimeType="text/plain" />
- </intent-filter>
- <intent-filter>
- <action android:name="android.intent.action.SEND_MULTIPLE" />
- <category android:name="android.intent.category.DEFAULT" />
- <data android:mimeType="image/*" />
- </intent-filter>
- </activity>
上面声明了三种intent-filter,当然可以更多,这里只是举个例子,
处理接收数据
声明了intent-filter,响应的Activity就要处理响应的数据,示例如下:
- public class ShareActivity extends Activity{
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- // Get intent, action and MIME type
- Intent intent = getIntent();
- String action = intent.getAction();
- String type = intent.getType();
- if (Intent.ACTION_SEND.equals(action) && type != null) {
- if ("text/plain".equals(type)) {
- handleSendText(intent); // Handle text being sent
- } else if (type.startsWith("image/")) {
- handleSendImage(intent); // Handle single image being sent
- }
- } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
- if (type.startsWith("image/")) {
- handleSendMultipleImages(intent); // Handle multiple images being sent
- }
- } else {
- // Handle other intents, such as being started from the home screen
- }
- }
- void handleSendText(Intent intent) {
- String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
- String sharedTitle = intent.getStringExtra(Intent.EXTRA_TITLE);
- if (sharedText != null) {
- // Update UI to reflect text being shared
- }
- }
- void handleSendImage(Intent intent) {
- Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
- if (imageUri != null) {
- // Update UI to reflect image being shared
- }
- }
- void handleSendMultipleImages(Intent intent) {
- ArrayList<Uri> imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
- if (imageUris != null) {
- // Update UI to reflect multiple images being shared
- }
- }
- }
通过声明intent-filter,处理接受到的数据就能完成分享的接收功能。
更多
上面只做了分享功能简单的说明,伴随着Android api的升级,也出现了一些新的完成“分享”功能的方法,比如 ShareActionProvider
,更多请参考。
0 0
- 使自己的应用出现在分享列表
- 让自己的应用出现在分享列表中。
- iOS应用开发,在系统分享列表中加入自己的应用
- android系统分享功能,将自己的APK加入可分分享的应用列表
- android分享功能以及将自己的应用添加到分享列表中(2)
- 将自己的应用添加到安卓系统的可分享应用列表中
- 怎样将自己的应用加入系统的分享选择列表?
- 在Android系统中如何给应用增加分享功能,怎样将应用加入系统的分享选择列表?
- iOS处理分享时,在三方应用中无法返回自己应用的问题
- iOS App让自己的应用在其他应用中打开列表中显示
- 让自己的应用在其他应用中打开列表中显示
- iOS App让自己的应用在其他应用中打开列表中显示
- ios App 让自己的应用在其他应用打开列表显示
- 让自己的应用在其他应用中打开列表中显示
- 让自己的软件出现在选择打开列表的软件中
- 让自己的app出现在某类格式文件的默认打开列表中
- Android应用如何触发应用出现在打开文件方式的列表中
- Android 分享功能(一)添加自己应用到系统分享列表
- reportviewer 解决按钮tips英文问题
- 游戏公司日记(5)
- Makefile 的变量-2
- Python正则表达式的用法
- Leetcode_subsets
- 使自己的应用出现在分享列表
- mysql常用命令
- Chapter 1 Hello, world of concurrency in C++!
- svn: 方法 OPTIONS 失败于 “https://192.168.1.110/svn/amlogic_mx/software/turnkey_src”: SSL handshake fail
- MyBatis_与spring的整合之添加事务
- struts2 拦截器 登录权限验证
- 03 Linux中C语言头文件位置
- 吞吐量(Throughput)、QPS、并发数、响应时间(RT)对系统性能的影响
- mysql存储过程中两个CURSOR嵌套使用遇到的有关问题