Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何向用户显示SD卡中的文件?_Android - Fatal编程技术网

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

Android 如何向用户显示SD卡中的文件?,android,Android,我想使用intents向用户显示我的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);

我想使用intents向用户显示我的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文件以便用户可以安装它。

试试这个

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