如何在用户的SD卡中显示文件?

时间:2011-08-03 12:32:36

标签: android

我想使用意图向用户显示我的apk文件,这里是代码:

 SDCardRoot = Environment.getExternalStorageDirectory();
 File file = new File(SDCardRoot,fileName);
 if (file.exists()) {

Uri path = Uri.fromFile(file);
Intent intent = new    
Intent(Intent.ACTION_VIEW,path);                                
startActivity(intent);

但它给了我ActivityNotFoundException,我想启动apk文件,以便用户可以安装它。

1 个答案:

答案 0 :(得分:0)

试试这个?

Uri path = Uri.fromFile(file);
Intent intent = new    
Intent(Intent.ACTION_VIEW,path);
intent.setDataAndType(path, "application/vnd.android.package-archive");                    
startActivity(intent);