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

这个link给出了答案,但要注意它的前提:

1 – This technique is only useful and just will work for you if you will make an application for a specific device you have its certificate, just like me.

你必须拥有测试机的证书
2 – Doing this technique you will access classes that the Google doesn’t guarantee its portability to future versions;

使用了hiden API,这些API可能在未来版本的Android中不支持
3 – I used and tested it in version 2.2;

Android2.2上可以通过
4 – You need remember put the permission in your AndroidManifest.xml.
<uses-permission android:name="android.permission.INSTALL_PACKAGES"/>

源代码在https://github.com/paulononaka/Android-InstallInBackgroundSample

可以看到作者使用了Java Reflection来call hidden Api InstallPackage

http://paulononaka.wordpress.com/2011/10/19/apk-with-system-privileges/这篇文章介绍了如何获得缺省的Android手机证书,比如Android Emulator。

 

Note:

  1. http://stackoverflow.com/questions/5803999/install-apps-silently-with-granted-install-packages-permission
  2. a way to install apk programmatically
    new an intent of action: android.intent.action.VIEW
    set type to “application/vnd.android.package-archive”
    set data to the path of the apk
    codes is like below:
    File f = Environment.getExternalStorageDirectory();  
    String fS = f.getAbsolutePath();
    Intent promptInstall = new Intent(Intent.ACTION_VIEW);
    Uri u = Uri.parse("file://"+fS+"/download/animalsounds.apk");
    String t = "application/vnd.android.package-archive";
    promptInstall.setDataAndType(u, t);
    Log.i(TAG+"installmenu.menucallback", u.getPath());
    startActivity(promptInstall);