0

From download manager I am able to download the updated APK. After successfully download Installation POP UP is coming for Install or Cancel. Is there any way to install the APK without asking for INSTALL. Because If I click on out side of POPUP the POPUP went off.

 Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(new File(path)),
                "application/vnd.android.package-archive");

        intent.setAction(Intent.ACTION_INSTALL_PACKAGE);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); 
David Wasser
  • 93,459
  • 16
  • 209
  • 274
u_pendra
  • 908
  • 1
  • 10
  • 25

5 Answers5

3

Below method look for a predefined mark on data/local and try to install apk files which are in /system/preinstall directory (which you can change).

In your usage delete apks_installed touch. On next boot android will install apks in preinstall directory

add a service which runs at start (init.d) scripts

service blabla /system/bin/blabla.sh
user root
group root
disabled
oneshot

write a blabla.sh file and put it in /system/bin/ directory

#!/system/bin/sh

MARK=/data/local/apks_installed
PKGS=/system/preinstall/

if [ ! -e $MARK ]; then

busybox find $PKGS -name "*\.apk" -exec sh /system/bin/pm install {} \;

touch $MARK
fi

Note: as you may realize you also need to install busybox

I may made some mistakes but i think you understand the point

Abbas Elmas
  • 422
  • 6
  • 16
1

Generally, you need the device to be rooted or to have the System firmware signature.

You can create a copy of ApplicationManager and OnInstalledPackaged in your App.

Using that you can run something similar to this:

public static void installApp(Context context, File path, OnInstalledPackaged callback) {
    try {
        final ApplicationManager am = new ApplicationManager(context);
        if(callback != null) am.setOnInstalledPackaged(callback);
        am.installPackage(path);
    } catch (Exception e) {
        if(Utils.LOGGING) Utils.log("E::"+e.toString());
    }
}
Knossos
  • 15,802
  • 10
  • 54
  • 91
  • actually this doesnt solve the main problem of the 'promt to the user' – bricklore Apr 23 '15 at 13:43
  • It does - I use this code on a device I have the firmware certificate for. It installs without a prompt. – Knossos Apr 23 '15 at 13:44
  • @Knossos how do you get the firmware certificate? – Caner Apr 23 '15 at 13:47
  • @Caner: You need to make the firmware, or know the people that do and ask them for it. – Knossos Apr 23 '15 at 14:03
  • And as you just said, it does not solve the problem, because the average user is not willing to build a system on their own. – bricklore Apr 23 '15 at 14:19
  • The original poster said nothing about requiring it to be run on the average users device. In another comment, he even remarks about it only being run on a rooted phone. – Knossos Apr 23 '15 at 14:23
1

Yes you can install apk silently by making your app system app and then running command pm install something like this:

private boolean installApk(String apkPath) 
{
  Command installEvent = new Command(getCommandList("pm install "
        + apkPath));
  return installEvent.executeCommandList();      
}

It worked for me.

blackgreen
  • 34,072
  • 23
  • 111
  • 129
tanmeet
  • 220
  • 2
  • 11
0

No, this is not possible for security reasons. You can initiate the installation but it is up to the user to decide.

However if the phone is rooted there is a way to do this programmatically but this is not an option for most of the apps out there. Code is similar to this:

public ApplicationManager(Context context) throws SecurityException, NoSuchMethodException {

    observer = new PackageInstallObserver();
    pm = context.getPackageManager();

    Class<?>[] types = new Class[] {Uri.class, IPackageInstallObserver.class, int.class, String.class};
    Class<?>[] uninstalltypes = new Class[] {String.class, IPackageInstallObserver.class, int.class};
    method = pm.getClass().getMethod("installPackage", types);
    uninstallmethod = pm.getClass().getMethod("deletePackage", uninstalltypes);
}


public void uninstallPackage(String packagename) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
        uninstallmethod.invoke(pm, new Object[] {packagename, observer, 0});
}
public void installPackage(Uri apkFile) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
        method.invoke(pm, new Object[] {apkFile, observer, INSTALL_REPLACE_EXISTING, null});
}

More details here:

install / uninstall APKs programmatically (PackageManager vs Intents)

https://paulononaka.wordpress.com/2011/07/02/how-to-install-a-application-in-background-on-android/

Community
  • 1
  • 1
Caner
  • 57,267
  • 35
  • 174
  • 180
0

You can't Install apk without user Interaction as you application is not system level

But In samsung Devices If you take enterpriase licence from samsung You can Install&uninstall apps silently

pavanmvn
  • 749
  • 10
  • 21