美文网首页 安卓
将自己的应用加入系统的打开方式和分享列表中

将自己的应用加入系统的打开方式和分享列表中

作者: 非爱狂风 | 来源:发表于2017-03-09 09:05 被阅读382次

    1、分享列表中显示自己的应用
    在用系统默认的分享功能都会调用系统中可分享的应用的一个列表,但是如何使自己的应用加入这个列表呢?首先需要配置androidmanifest.xml,在分享页面的activity加入下边的filter
    <intent-filter>
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="text/plain" />
    </intent-filter>
    这样就可以过滤分享文本的时候自己的应用出现在列表中。
    接受内容,在对应的activity中intent中获取相关的数据
    title = intent.getStringExtra(SHARE_IMG_TITLE);
    (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM)
    具体的mimeType类型有
    {".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"},
    {"", "/"}

    2、打开方式中增加自己的应用
    安卓中的文件打开一般都会让选择打开方式,看到所有文件的打开方式中都有QQ,而QQ是直接发送给了好友,其实也算是一种分享,具体方法和分享类似只是filter名字是view
    <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="image/*" />
    </intent-filter>

    相关文章

      网友评论

        本文标题:将自己的应用加入系统的打开方式和分享列表中

        本文链接:https://www.haomeiwen.com/subject/flfwgttx.html