我有一个应用程序,我使用zxing barcode scanner
扫描qr codes
。这只工作,如果用户安装barcode scanner
应用程序在他的手机。那么,我可以在安装我的应用程序时自动安装该应用程序吗?像安装apk file
编程或集成的apk与我的等,以便用户需要再次手动安装该应用程序。
是的,我认为你可以,把apk放在你的内部存储,然后使用intent你可以用编程方式安装它,首先检查Android包管理器是否在设备中可用,如果没有,然后安装它,
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(path+"/Bscanner.apk")), "application/vnd.android.package-archive");
startActivity(intent);
但是如果可能的话,你必须将Zxing库集成到你的android应用程序中并使用它,所以你不必在设备上安装Bar-code Scanner apk .
安装代码....
String vsName=Environment.getExternalStorageDirectory().getAbsolutePath()+"/download/";
File file = new File(vsName, "aaa.apk");
System.out.println(":"+file);
Intent install=new Intent(Intent.ACTION_VIEW);
install.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(install);
你可以让用户安装你的应用程序,并在第一次运行时启动Intent
来下载其他应用程序。用户必须手动安装应用程序,但至少它会自动下载。
编辑: user370305的Intent
解决方案似乎是启动安装的好方法。由于所有下载都在sd卡上的共享目录中,因此可以从下载目录启动安装。