Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "app.apk")), "application/vnd.android.package-archive");
startActivity(intent);
This was found here: Question [4967669] android-install-apk-programmatically
Using an android Service if do this I get the following error message:
05-03 08:24:14.559: E/AndroidRuntime(21288): FATAL EXCEPTION: Thread-1706 05-03 08:24:14.559: E/AndroidRuntime(21288): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
I added the FLAG_ACTIVITY_NEW_TASK:
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
But now nothing happens. No error but also no attempt to install the apk. I am thinking it might be because it has no activity (since it is a service)?
QUESTION Is it possible to install an APK via android background service? (if so) does any one knwo how do I do it?
Thanks in Advance
PS: From my understanding of services they are very much like activities so not sure why this wont work.