冰浪

          哥已不再年輕 - 堅定夢想,畢生追求!
          posts - 85, comments - 90, trackbacks - 0, articles - 3
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          通過Intent啟動程序來查看文件

          Posted on 2010-01-22 00:15 冰浪 閱讀(385) 評論(0)  編輯  收藏 所屬分類: Android

          操作系統(tǒng)都有一套”血緣關(guān)系“列表,它用于標識所有可識別的類型文件的查看方式,例如:Mp3 ->Windows Media Player、Txt -> Notepad、JPG -> Picasa等等。相同的,在Android中也提供了這樣一種機制,當用戶想查看存儲器中的某些文件時,將通過Intent找到啟動這種類型文件的程序。

          這里提供兩個用于查看MP4和MP3的例子作為參考:


          Intent intent = new Intent(); 
          intent.setAction(android.content.Intent.ACTION_VIEW); 
          File file = new File("/sdcard/test.mp4"); 
          intent.setDataAndType(Uri.fromFile(file), "video/*"); 
          startActivity(intent);    

          Intent intent = new Intent(); 
          intent.setAction(android.content.Intent.ACTION_VIEW); 
          File file = new File("/sdcard/test.mp3"); 
          intent.setDataAndType(Uri.fromFile(file), "audio/*"); 
          startActivity(intent);


          【http://www.androidres.com/index.php/2009/05/08/android-intent-tutorials-open-file-with-a-suitable-app/

          主站蜘蛛池模板: 乐都县| 镇坪县| 西畴县| 渝中区| 米脂县| 道孚县| 慈溪市| 潍坊市| 赫章县| 永济市| 宁晋县| 阿拉善盟| 历史| 酒泉市| 翁源县| 五莲县| 定远县| 寿光市| 安溪县| 沭阳县| 麦盖提县| 宜昌市| 忻州市| 松滋市| 宁阳县| 武冈市| 龙井市| 金川县| 新竹县| 台州市| 丘北县| 犍为县| 自贡市| 巴青县| 宜春市| 湖北省| 兖州市| 扶余县| 侯马市| 江陵县| 山阴县|