冰浪

          哥已不再年輕 - 堅定夢想,畢生追求!
          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)系“列表,它用于標(biāo)識所有可識別的類型文件的查看方式,例如:Mp3 ->Windows Media Player、Txt -> Notepad、JPG -> Picasa等等。相同的,在Android中也提供了這樣一種機制,當(dāng)用戶想查看存儲器中的某些文件時,將通過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/

          主站蜘蛛池模板: 姜堰市| 泽库县| 洪雅县| 剑河县| 富裕县| 连山| 佛山市| 泰安市| 特克斯县| 漾濞| 德化县| 永顺县| 当阳市| 日照市| 赣榆县| 昌江| 永顺县| 临西县| 保康县| 上虞市| 永年县| 玉山县| 抚宁县| 东至县| 开江县| 泰顺县| 塔城市| 芜湖县| 罗江县| 博客| 集贤县| 邹城市| 佛山市| 彭山县| 威信县| 临潭县| 若尔盖县| 突泉县| 普兰店市| 龙井市| 时尚|