我正在开发关于apk文件运行的android应用程序。我可以将apk文件下载到我的本地存储但我无法运行此apk文件如何在android中运行已安装的apk文件?我试过下面的代码,但是我收到了一个错误
public class DownloadApkMainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_download_apk_main);
Intent installIntent = new Intent(Intent.ACTION_VIEW);
installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
installIntent.setDataAndType(Uri.parse("/mnt/sdcard/" + "/MyFavorite/"+ "Anket4.apk"), "application/vnd.android.package-archive");
startActivity(installIntent);
}
}
答案 0 :(得分:1)
而不是
installIntent.setDataAndType(Uri.parse("/mnt/sdcard/" + "/MyFavorite/"+ "Anket4.apk"), "application/vnd.android.package-archive");
试
installIntent.setDataAndType(Uri.fromFile(new File("/mnt/sdcard/" + "/MyFavorite/"+ "Anket4.apk")), "application/vnd.android.package-archive");