Android文件执行

问题描述:

我在做一个Android文件浏览器。我怎样才能执行一个文件? 例如:“/xxx/xxx/image.jpg” 当用户单击文件名时,我需要在默认的android系统图像查看器中显示图像。Android文件执行

+0

您需要发送一个意图。我认为这个答案可能会帮助你:http://*.com/a/17831722/4568679 – Slav

您可以使用意图来做到这一点。

Intent intent = new Intent(); 
//Action View to see an image in default native app in your device. 
intent.setAction(Intent.ACTION_VIEW); 
//The path to see your image. 
intent.setDataAndType(Uri.parse("file://" + "/sdcard/test.jpg"), "image/*"); 
startActivity(intent); 

不知道太多关于代码本身,你可以尝试使用:

Intent intent = new Intent(); 
intent.setAction(Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.parse("file://" + "your_image_path.jpg"), "image/*"); 
startActivity(intent); 

ACTION_VIEW按照Android文档:

显示的数据传送给用户。这是对数据执行的最常见动作 - 这是您可以使用的一项数据上的一般操作,以获得最合理的事情发生。