I know I can install an Android application programmatically by the below code which passes the URI of an APK file. Can I install the application without passing an APK file URI? For example, getting the byte array of an APK file and installing it?
File appFile = new File("application.apk");
Intent installIntent = new Intent(Intent.ACTION_VIEW);
installIntent.setDataAndType(Uri.fromFile(appFile),"application/vnd.android.package-archive");
startActivity(installIntent);
When you install an application this way, you aren't actually directly installing the application. What happens is that you start the installer and pass the installer a reference to the APK that you want to have installed. The installer isn't part of your application code and has no access to the memory in your application's process.
The only way to do this, if you have a byte array containing the APK, would be to write the byte array to a file and then start the installer and pass it a URI that points to the file that you've written. Once the installation is complete you could then delete the file (so as not to leave random garbage on the user's phone).
Related
I'm trying to download an APK file online from within my app and then install it using Java. My code basically, downloads the file to the device from my server and then uses an Intent to open the installation message from the package manager and allow the app to be installed.
It works perfectly for me... unless I save the file to cache instead of regular storage. If I save it to cache instead, I get an error that it could not parse the APK file.
I checked and it is downloading the entire file to the cache correctly, but it just not installing. Any ideas?
The only difference in my code is that instead of using Environment.getExternalStorageDirectory() + "/file.apk" I'm trying to use context.getCacheDir() + "/file.apk" as for my file path.
I want to put the file in the cache so that Android can handle the cleaning of the file and so that I don't need to worry about handling write permissions on different Android versions and the variations of dealing with external storage.
I want to make my application as a system application. But my application crashes when i make it as system app (placed .apk file inside System/app).
It crashes because its not able to load .so files.
My first question here is do i need to copy the libs( Extract .apk and i will be getting libs) inside System/libs or the System automatically does it?
My Second question here is does the system load libraries(.so files) from System/libs or data/data/myApp.PackageName/lib folder?
Any Help would be Appreciated.
My first question here is do i need to copy the libs( Extract .apk and i will be getting libs) inside System/libs or the System automatically does it?
You don't need to manually copy the .so files.
But, please double check why
It crashes because its not able to load .so files.
you need to ensure that you have the corresponding ABI for your target phone, e.g. you need to have arm64-v8a for your real devices, but this ABI won't work for emulators as usually emulators are x86 or x86_64.
My Second question here is does the system load libraries(.so files) from System/libs or data/data/myApp.PackageName/lib folder?
From data/data/myApp.PackageName/lib
I am developing a android app and I am supposed to download some data to a folder on sdcard from dropbox folder and once the download is complete only then the app can start.
The problem is I have some files available on my sdcard folder which are also present on dropbox folder along with some other files ,and now when I start my app I should be able to download only those files which are not there on my sdcard folder. How should I go by it? Thanks.
When you download any files from Dropbox, store the rev value from the Dropbox file's metadata.
Later, when you check again, if the remote rev matches your local value, you know you still have the same version. If not, download the new version.
Just checking the filename and file size is error prone, since two different versions of a file can have the same size.
Edit: The Dropbox API now offers a hash of file data that you can use to verify a file's contents. In the API v2 Java SDK, it's available as FileMetadata.contentHash.
It isn't a single MD5 or SHA1, but rather a combination of SHA256 hashes of the pieces of the file. You can find more information here:
https://www.dropbox.com/developers/reference/content-hash
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I know how to install an application to an Android device e.g from Play-Store or via an .apk file. But I'd like to understand the actual process of installation.
E.g. on Windows:
Serial codes etc. are placed in the registry
Files important to the running of software are placed within the Program Files folder (the main .exe etc.)
So far, what I do know about the Android application installation process is:
After an android application has been executed (post-installation), data freshly downloaded is placed in locations like: Android/data or Android/obb etc.
If specifically expressed by an Android developer, files can also be placed elsewhere e.g. on secondary storage (memory cards, cloud storage etc.)
But other than that, my knowledge concerning the Android installation process is pretty slim e.g.:
I don't know where important files relating to an Android program's execution are placed (in the case of Windows, the .exe, related media, libraries etc.)
I similarly don't know how these files are structured upon an Android device (post-installation) e.g. are these files structured in folders like: java, res, menu, layout etc. as during development within environments like Android Studio?
Neither do I know how what application file-types are stored on a user's device post-installation (after being unpacked from the android installation file or apk) e.g. are they stored as .java and or .xml files, as during development etc.
Hopefully someone can fill in the blanks, thank you.
Beginnning
PackageInstaller calls InstallAppProgress activity to receives an instruction from the user. InstallAppProgress will ask PackageManager Service to install package via installd. Source code is available at <Android Source>/packages/apps/PackageInstaller.
When we install APK file, Package Manager parse the package(APK) file and display confirmation, When user press OK button, Package Manager call method named installPackage with these four parameters namely uri, installFlags, observer, installPackageName. Package Manager start one service named "package", now all fuzzy things happen in this service. you can check PackageInstallerActivity.java and InstallAppProgress.java in PackageInstaller source code. Package Manager Service running in system_service process and install daemon (installd) that runs as a native process both start at system boot time.
Where APK files stores in Android ?
Pre-Install (i.e. Camera, Calendar, Browser,etc.) APK stored in /system/app/
User Install (ApiDemo, Any.do, etc.) APK stored in /data/app/
Package Manager create data directory /data/data/<package name>/ to store database, shared preference, native library and cache data
You might see apk file and *.odex file for same APK, ODEX file is totally different discussion and purpose.
What is APK installation process in detail ?
Following process execute in Package Manager Service.
Waiting
Add a package to the queue for the installation process
Determine the appropriate location of the package installation
Determine installation Install / Update new
A copy of the apk file to a given directory
Determine the UID of the app
Request to installd daemon process
Create the application directory and set permissions
Extraction of dex code to the cache directory
To reflect and packages.list /system/data/packages.xml the latest status
Broadcast to the system along with the name of the effect of the installation is complete package
Intent.ACTION_PACKAGE_ADDED: If the new ( Intent.ACTION_PACKAGE_REPLACED): the case of an update.
How Package Manager store data ?
Package Manager store application information in three files, located in /data/system. Following sample is extracted from Android 4 ICS emulator image.
packages.xml:This file contain list of permissions and Packages/Applications.
This xml file stores two things 1. permissions 2. package (application), permission are store under <permissions> tag. Each Permission has three attributes namely name, package and protection. Name attribute has permission name which we are using in AndroidManifest.xml, package attribute indicate permission belong to package, In majority cases "android" is values because <permission> tag contain default permissions and protection indicate level of security.
packages.list: It is simple text file contain package name, user id, flag and data directory, I can't find any perfect description but I assume it that packages.list file may provide faster lookup of installed package because it file keep important information only.
com.android.launcher 10013 0 /data/data/com.android.launcher
com.android.quicksearchbox 10033 0 /data/data/com.android.quicksearchbox
com.android.contacts 10001 0 /data/data/com.android.contacts
com.android.inputmethod.latin 10006 0 /data/data/com.android.inputmethod.latin
packages-stoped.xml: This file contain package list which has stopped state, Stope stated applications can not receive any broadcast.
Where I can find the source code of Package Manager and Package Installer ?
Package Manager
frameworks/base/services/java/com/android/server/pm/Settings.java
frameworks/base/services/java/com/android/server/pm/PackageManagerService.java
frameworks/base/services/java/com/android/server/pm/IPackageManager.aidl
frameworks/base/services/java/com/android/server/pm/PackageSignatures.java
frameworks/base/services/java/com/android/server/pm/PreferredActivity.java
frameworks/services/java/com/android/server/PreferredComponent.java
frameworks/core/java/android/content/IntentFilter.java
frameworks/base/core/java/android/content/pm/PackageParser.java
frameworks/base/services/java/com/android/server/pm/Installer.java
frameworks/base/core/java/com/android/internal/app/IMediaContainerService.aidl
frameworks/base/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java
Package Installer
packages/apps/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java
packages/apps/PackageInstaller/src/com/android/packageinstaller/PackageUtil.java
packages/apps/PackageInstaller/src/com/android/packageinstaller/InstallAppProgress.java.
Links to refer: link 1 and link 2.
I would like to install an APK from within an Android application. Can anyone give me an example of how to do this?
EDIT:
Also how do I open the install applications from unknown resources preference page so that users can change it?
EDIT:
I actually meant open the screen using code, so I can immediately open the preference page for the user to simply check the box, and press back. Is it possible to check to see if they allow non-market apps?
Can an application request permission enough to do this?
use an intent with the link of your apk file.
Intent intent = new Intent(Intent.ACTION_VIEW ,Uri.parse("http://movil.reforma.com/android/Android_Noticias_Reforma.apk"));
startActivity(intent);
install applications from unknown resources preference
go to
Settings > Applications > Unknow
sources