android - How to programmatically install an APK from a Service -
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 found here: question [4967669] android-install-apk-programmatically
using android service if 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() outside of activity context requires flag_activity_new_task flag. want?
i added flag_activity_new_task:
intent.addflags(intent.flag_activity_new_task);
but nothing happens. no error no attempt install apk. thinking might because has no activity (since service)?
question possible install apk via android background service? (if so) 1 knwo how do it?
thanks in advance
ps: understanding of services activities not sure why wont work.
you can install apk background service. try use uri.parse
instead of uri.fromfile
file apkfile = new file(environment.getexternalstoragedirectory() + "/download/" + "app.apk"); if (!apkfile.exists()) { return; } intent installintent = new intent(intent.action_view); installintent.setflags(intent.flag_activity_new_task); installintent.setdataandtype( uri.parse("file://" + apkfile.tostring()), "application/vnd.android.package-archive"); startactivity(installintent);
Comments
Post a Comment