I use the following code to install the application from my application, which I placed in the Android source code.
I compiled and created an emulator, I see that my application works fine inside an emulator created from an Android source.
At a certain point in my application, I try to install another application from my application. The APK path for the application I'm trying to install is:
/data/data/com.games.golf/cache/MyGames/Golf.apk
Below is the code that I use to install the application at the above path from my application:
private void InstallApplicaiton(String url) { PackageParser.Package mPackage = PackageUtil.getPackageInfo(Uri.parse(url)); installingList.addView(getProgressView(mPackage,url)); int installFlags = 0; PackageManager pm = getPackageManager(); try { PackageInfo pi = pm.getPackageInfo(mPackage.packageName, PackageManager.GET_UNINSTALLED_PACKAGES); if(pi != null) { System.out.println("Inside pi if not null"); installFlags |= PackageManager.INSTALL_REPLACE_EXISTING; } } catch (NameNotFoundException e) { e.printStackTrace(); } String installerPackageName = getIntent().getStringExtra( Intent.EXTRA_INSTALLER_PACKAGE_NAME); System.out.println("installerPackageName:"+installerPackageName); PackageInstallObserver observer = new PackageInstallObserver(); pm.installPackage(Uri.parse(url), observer, installFlags, installerPackageName); } private Handler mHandler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case INSTALL_COMPLETE: System.out.println("package installed"); break; } } }; class PackageInstallObserver extends IPackageInstallObserver.Stub { public void packageInstalled(String packageName, int returnCode) { Message msg = mHandler.obtainMessage(INSTALL_COMPLETE); msg.arg1 = returnCode; mHandler.sendMessage(msg); } }
I get a SOP message inside the handler from PackageInstallObserver that the package is installed. But I can not see the installed application in the launcher.
I am aware that third-party applications cannot install / uninstall APK programmatically. For this reason, I compiled and created an emulator by turning on my application so that I could install other applications from my application. But here, too, when I get confused with the code above, I don't know the reason.
I used the same code that android uses to install packages, but why the above code does not work and the package does not install, this is something that I can not understand.
The only problem I could notice is that String installerPackageName always null.
Any help in this regard that will help me solve this problem so that the package will be installed from my application would be greatly appreciated.
Edit
The following is a log. This is because I'm trying to install this from the emulator, as well as from the cache folder - /data/data/com.games.golf/cache . Does it have anything to do with permission when accessing this folder?
05-29 19:31:57.237: W/asset(7490): Asset path /data/data/com.games.golf/cache/MyGames/Golf.apk is neither a directory nor file (type=0). 05-29 19:31:57.237: W/DefContainer(7490): Failed to parse package 05-29 19:31:57.237: W/ActivityManager(79): No content provider found for permission revoke: /data/data/com.games.golf/cache/MyGames/Golf.apk 05-29 19:31:57.297: I/ActivityManager(79): Displayed com.games.golf/.screens.PackageInstaller: +448ms 05-29 19:31:57.607: D/dalvikvm(79): GC_EXPLICIT freed 71K, 11% free 8410K/9415K, paused 4ms+7ms