Android 實現文件打開方式可供選擇功能

比如通過文檔查看器打開一個文本文件時,會彈出一個可用來打開的軟件列表;

如何讓自己的軟件也出現在該列表中呢? 通過設置AndroidManifest.xml文件即可:

<activity android:name=".EasyNote" android:label="@string/app_name" android:launchMode="singleTask" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<data android:mimeType="text/plain"></data>
</intent-filter>
</activity>

第一個<intent-filter>標籤是每個程序都有的,關鍵是要添加第二個!這樣你的應用程序就會出現在默認打開列表了。。。

注意

需要將mimeType修改成你需要的類型,文本文件當然就是:text/plain

還有其它常用的如:

    text/plain(純文本)

    text/html(HTML文檔)

    application/xhtml+xml(XHTML文檔)

    image/gif(GIF圖像)

    image/jpeg(JPEG圖像)【PHP中爲:image/pjpeg】

    image/png(PNG圖像)【PHP中爲:image/x-png】

    video/mpeg(MPEG動畫)

    application/octet-stream(任意的二進制數據)

    application/pdf(PDF文檔)

    application/msword(Microsoft Word文件)

    message/rfc822(RFC 822形式)

    multipart/alternative(HTML郵件的HTML形式和純文本形式,相同內容使用不同形式表示)

    application/x-www-form-urlencoded(使用HTTP的POST方法提交的表單)

    multipart/form-data(同上,但主要用於表單提交時伴隨文件上傳的場合)


    網絡上查看的資料,有意思......


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章