I want to install an apk file from my application.
I have created an app that contains a button, when I click that button then another apk that I have stored in res
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
File DbFile=new File("mnt/sdcard/HelloAndroid.apk");
if(!(DbFile.exists()))
{
try
{
int length = 0;
DbFile.createNewFile();
InputStream inputStream = this.getAssets().open("HelloAndroid.apk");
FileOutputStream fOutputStream = new FileOutputStream(DbFile);
byte[] buffer = new byte[inputStream.available()];
while ((length = inputStream.read(buffer)) > 0)
{
fOutputStream.write(buffer, 0, length);
}
fOutputStream.flush();
fOutputStream.close();
inputStream.close();
}
catch (Exception ex)
{
System.out.println("Error in creating new database at mobile..." + ex);
ex.printStackTrace();
}
}
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File("/mnt/sdcard/HelloAndroid.apk")), "application/vnd.android.package-archive");
startActivity(intent);
}
Here i have stored my apk file in assets folder. You can try this.