冰浪

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

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

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

          操作系統都有一套”血緣關系“列表,它用于標識所有可識別的類型文件的查看方式,例如: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/

          主站蜘蛛池模板: 天等县| 水富县| 乌拉特后旗| 普兰县| 邹平县| 潞城市| 内黄县| 定州市| 龙口市| 曲水县| 玉山县| 刚察县| 盖州市| 池州市| 濮阳县| 郎溪县| 东台市| 白城市| 井研县| 廉江市| 龙海市| 安达市| 客服| 安泽县| 吕梁市| 瓮安县| 冷水江市| 枞阳县| 湾仔区| 平远县| 宝鸡市| 安国市| 吉安县| 武山县| 博爱县| 阳西县| 邵东县| 自治县| 惠来县| 隆昌县| 博罗县|