Android 如何向用户显示SD卡中的文件?
我想使用intents向用户显示我的apk文件,下面是代码: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);
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);