冰浪

哥已不再年轻 - 坚定梦想,毕生追求!
posts - 85, comments - 90, trackbacks - 0, articles - 3
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

通过Intent启动程序来查看文件

Posted on 2010-01-22 00:15 冰浪 阅读(365) 评论(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/


只有注册用户登录后才能发表评论。


网站导航: