I need to downloads and install apk from server to devices and i tried to do this task but it ask for user permission like "Insall" , "Cancel" . and if hits "Install" then it works fine and installed but i dont need this permission as i am to install 30 apk from server .
Thanks in advance .
The security model of android won't let you do such things without user interaction. It could be, if the particular phone was rooted, but I think you can't rely on that.
You can not do this on Android as said because it's a security limitation.
It could be possible if you create a system app but based on your question I think that is not what you are after.
However there is a possible workaround:
If those apps that you are installing are made by you and it is possible to modify them to act like plugins/libraries(Don't worry you can keep the activities and stuff) then you could load them dynamically when your apk is run, thus essentially giving you new code to be run on the device (Elements of these apps will run under same user ID but you can start them in a new process if you want with android:process=":YourProcessName".
Check out this tutorial on how to load external libraries at runtime http://xianminx.blogspot.com/2011/12/dynamic-loading-android-custom-library.html
Related
I want to access the apk file of any app before installation.
In more details: in google play store when the user clicks on Install button I want my application to access the apk file of the application that the user wants to download, and analyze this apk file and be able to whether allow the installation or stop it.
is that possible and if so how to approach this
On Android this functionality was introduced in Android 4.2. It is usually used by anti-malware products like Google Play Protect is known as a "Package Verifier". There is a good blog post on it here.
The short answer is this has to be done as part of the phone manufacturing process as it is so critical to security. So the answer is it can be done, but if you write this code you will need to get a phone manufacturer to include your code as part of a phone system image.
Most third party anti-malware products instead rely on analyzing the APK after the install happens by listening to the package added notification.
Definitely not possible in the way that you want. Android's OS is pretty well locked down. You might be able to do something if the device was rooted but at that point you may as well write your own OS fork. You can attempt to do someting with https://developer.android.com/reference/android/content/Intent.html#ACTION_PACKAGE_ADDED broadcast but you will not be able to analyze the apk freely nor will you be able to stop the installation of it.
Background
Starting from Android 6, each time you install an app, you need to grant its permissions during runtime.
The problem
This can become really annoying when running apps from the IDE, as you need to re-grant the permissions every time you want to try out the app (if it wasn't installed), which is tedious operation, especially if you have multiple permissions.
Of course, it's important to test the app this way too, because that's how users will use the app, but starting from certain point at time, it's not needed, because you already handled it fine
What I've tried
Only thing I've found is how to create a new gradle task for this (here), but this doesn't work together with the installation. Instead, I need to run it separately, but for this I can just use a batch file anyway, using adb commands.
Another thing I've found (here) is something that does it, but also re-install (meaning you install the app two times instead of once, each time you want to do it) the app before launching it for some reason, so this is not a good solution.
The question
Is there a way that upon installation of the app via the IDE, all permissions will be auto-granted?
The device my Android app is running does not have Playstore on it. The plan is to pre-install the software when shipping the device. I am now looking for a strategy to upgrade the application.
I found this useful link to install an Android app from the apk file:
Android: install .apk programmatically
I am thinking I will use this logic to auto-upgrade my app. I am wondering if it is even possible. I am thinking the upgrade will first try to uninstall existing version but will fail as the executable is still running and the file may be locked. Is there a better way? Regards.
Peter, we've just implemented the same thing.
Users have the software pre-installed on their device and we host update APK's on the companies servers.
From the app they can then check for updates where we have a WCF service which extracts the APK file (essentially a .zip) and returns the manifest details. From there we have the version of the APK and can compare it against the local version.
If the user decides to upgrade they can download the APK and you can automatically launch it. At which point the user will be told the application is going to be updated. There are no file locks etc, the app will just close and restart using the new version.
Note: Downgrading is not "automatic". The user would have to first uninstall the app. For upgrades, however, it's a simple case of downloading and launching the APK version (the user will be told they need to allow installations from unknown sources if this is not checked).
You have a couple of options, depending upon your target system.
Use the link you posted. This will provide the user with a traditional install dialog, whereby the user can choose to install or not. You should avoid doing that automatically, as APKs can be large and you might irritate the user if they don't want updates.
You can install updates magically, but you will require the firmware signing key (or possibly root, but I haven't tested that). That will not ask for consent from the user. You will need to add additional code using reflection to access the installation methods of Android. If you go this way, you should build an opt-out/in mechanism.
If your app is open-source, F-Droid would solve the problem for you.
F-Droid is an installable catalogue of FOSS (Free and Open Source
Software) applications for the Android platform. The client makes it
easy to browse, install, and keep track of updates on your device.
Mainly, it updates your app when necessary. (Or just have a look at its source code for inspiration on how to do it).
Yes but as far as I remember only if you had Root privileges in order to have access to the INSTALL_PACKAGES permission.
If a user downloads my app (a .apk file) onto their android phone from the market place,
Where does the .apk file end up on their phone?
When they're running my application, if I detect that there is a new later version of the application available is it possible to from within the application that they're running download the latest version off an ftp link (I can programmatically do that now) and then replace the existing .apk that they're now running with the newer version. [Not sure about this one at all.]
Is the existing application all in memory when it's being run, so that when i download the new version, I can delete its apk file without it being locked up and replace it with the later build and then restart the app?
What's the best way to handle this scenario? I have an app where I want to ensure that users are on the latest version before they use it.
Apps are stored in /data/app see https://android.stackexchange.com/questions/3002/where-in-the-file-system-are-applications-installed.
IMHO, You should let the market manage updates for you, there's no need to bother doing anything by hand and as an user I would be "angry" if some app start downloading stuff on my phone without my consent, especially when abroad (some users are paying their datas).
If this user has rooted phone, you may use code provided in this answer: Android silent apk update.
If not, user has to be prompted, and you may start an activity with an intent (as usual), but also, before calling startActivity(intent), call intent.setDataAndType(Uri.fromFile(...)).
I developed android application and put .apk on my website which runs on LAMP and I wish to enable somehow OTA (over the air) installation of my application, by simply providing URL to Android device.
How can I do it?
Scenario I wish to produce is (if someone didn't understand me correctly) that user scanns QR code of apk's URL and then install it seemlessly. Right now, user must download the file, then tap on it to install it.
Thanks in advance.
Just have the QR code point to the actual .apk and let the user download it and manually install it. There is no way to have a user read the QR and upon that automatically install the app. Thats not how OTA installations nor updates work. Even when you perform an actual OTA update of Android for example you have to confirm that you'd like the action to be performed.
Even if there is a way to achieve this it won't hinder anyone to just pull the .apk from his phone and take a look at it or reverse engineer it.
You may also see what adb install testapp.apk does and how it works...
Maybe you can initiate it from your app, once you download the new version to the phones (SD Card)