Android:添加自己的应用到“分享”->"发送文件"选项
来源:互联网 发布:linux netlink 编辑:程序博客网 时间:2024/05/20 05:10
本文参考:
http://eggie5.com/8-hook-share-picture-via-menu-android
1. 增加Intent-Filter,使得当前应用会出现在特定文件共享功能菜单里
以下示例代码表示任何类型的文件"共享"(Share via)菜单都会出现当前应用。
<intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="*/*" /> </intent-filter>
http://www.iana.org/assignments/media-types
常见类型:
{".3gp", "video/3gpp"}, {".apk", "application/vnd.android.package-archive"}, {".asf", "video/x-ms-asf"}, {".avi", "video/x-msvideo"}, {".bin", "application/octet-stream"}, {".bmp", "image/bmp"}, {".c", "text/plain"}, {".class", "application/octet-stream"}, {".conf", "text/plain"}, {".cpp", "text/plain"}, {".doc", "application/msword"}, {".exe", "application/octet-stream"}, {".gif", "image/gif"}, {".gtar", "application/x-gtar"}, {".gz", "application/x-gzip"}, {".h", "text/plain"}, {".htm", "text/html"}, {".html", "text/html"}, {".jar", "application/java-archive"}, {".java", "text/plain"}, {".jpeg", "image/jpeg"}, {".jpg", "image/jpeg"}, {".js", "application/x-javascript"}, {".log", "text/plain"}, {".m3u", "audio/x-mpegurl"}, {".m4a", "audio/mp4a-latm"}, {".m4b", "audio/mp4a-latm"}, {".m4p", "audio/mp4a-latm"}, {".m4u", "video/vnd.mpegurl"}, {".m4v", "video/x-m4v"}, {".mov", "video/quicktime"}, {".mp2", "audio/x-mpeg"}, {".mp3", "audio/x-mpeg"}, {".mp4", "video/mp4"}, {".mpc", "application/vnd.mpohun.certificate"}, {".mpe", "video/mpeg"}, {".mpeg", "video/mpeg"}, {".mpg", "video/mpeg"}, {".mpg4", "video/mp4"}, {".mpga", "audio/mpeg"}, {".msg", "application/vnd.ms-outlook"}, {".ogg", "audio/ogg"}, {".pdf", "application/pdf"}, {".png", "image/png"}, {".pps", "application/vnd.ms-powerpoint"}, {".ppt", "application/vnd.ms-powerpoint"}, {".prop", "text/plain"}, {".rar", "application/x-rar-compressed"}, {".rc", "text/plain"}, {".rmvb", "audio/x-pn-realaudio"}, {".rtf", "application/rtf"}, {".sh", "text/plain"}, {".tar", "application/x-tar"}, {".tgz", "application/x-compressed"}, {".txt", "text/plain"}, {".wav", "audio/x-wav"}, {".wma", "audio/x-ms-wma"}, {".wmv", "audio/x-ms-wmv"}, {".wps", "application/vnd.ms-works"}, //{".xml", "text/xml"}, {".xml", "text/plain"}, {".z", "application/x-compress"}, {".zip", "application/zip"}, {"", "*/*"}
如果需要匹配特定类型,特定文件,可以用正则表达式,这里给出<data>参考链接:
http://developer.android.com/guide/topics/manifest/data-element.html
2.添加相应的处理代码
@Overrideprotected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Intent intent = getIntent();Bundle extras = intent.getExtras();String action = intent.getAction();// 判断Intent是否是“分享”功能(Share Via)if (Intent.ACTION_SEND.equals(action)){if (extras.containsKey(Intent.EXTRA_STREAM)){try{// 获取资源路径UriUri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);Log.i(TAG, "uri:" + uri.toString());//解析Uri资源ContentResolver cr = getContentResolver();InputStream is = cr.openInputStream(uri);// Get binary bytes for encodebyte[] data = getBytesFromFile(is);return;}catch (Exception e){Log.e(this.getClass().getName(), e.toString());}}else if (extras.containsKey(Intent.EXTRA_TEXT)){return;}}
- Android:添加自己的应用到“分享”->"发送文件"选项
- Android:添加自己的应用到“分享”->"发送文件"选项
- android 关于将应用添加到系统的 分享.. 或者 发送到.. 中
- android 关于将应用添加到系统的 分享.. 或者 发送到.. 中
- android分享功能以及将自己的应用添加到分享列表中(2)
- android 添加自己的应用到打开为里面的选项里
- Android 分享功能(一)添加自己应用到系统分享列表
- android把自己的应用加入到系统分享中
- Android Notes - 添加Copy to Clipboard的选项到分享列表中
- 添加WidgetView到自己的应用
- 如何给Android应用添加分享到新浪微博
- Android 相册图片 添加应用到分享列表
- Android Share 将图片或者文件分享到自己的APP 中
- 如何快速添加快捷方式到“发送到”选项...
- Google Android开发者文档系列-创建有内容分享特性的应用之发送简单数据到其它应用程序
- iOS App让自己的应用在其他应用中打开列表中显示、iOS把自己的应用添加到”活动“、将PDF文件Open In MyApp
- iOS App让自己的应用在其他应用中打开列表中显示、iOS把自己的应用添加到”活动“、将PDF文件Open In MyApp
- 添加分享到朋友圈、发送给好友、分享等按钮
- 几道js笔试题
- 归并排序C语言实现MergeSort
- 创建由jQuery Mobile驱动的移动web应用程序
- 安装opengl
- sicily 1029 Rabbits
- Android:添加自己的应用到“分享”->"发送文件"选项
- 类加载器和动态代理
- Linux 之 shell 比较运算符
- 两个小点
- 序列化Serializable的理解
- Linux进程的实际用户ID和有效用户ID
- Mybatis
- red hat 下alternatives命令用法
- acm~北大oj分类