You cannot do that as our friends advised you. I have tried by these ways for installing APK from my own server
- You can download the APK from the server and save it in some folder
- Add permission in manifest
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Use this demo code for downloading and installing the APK
Downloading APK from server
String PATH = Environment.getExternalStorageDirectory()+ "/yourpath/";
File file = new File(PATH);
if (!file.exists()) {
file.mkdirs();
}
File outputFile = new File(file,
"your.apk");
if (outputFile.exists()) {
outputFile.delete();
}
FileOutputStream fileOuputStream = new FileOutputStream(
outputFile);
fileOuputStream.write(bResponse);
fileOuputStream.close();
Installation of APK after Download completes
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(Environment
.getExternalStorageDirectory()+ "/your path/"+ "yourapkname.apk")),
"application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
3.After Installation you can delete the APK from folder location