Chinaunix首页 | 论坛 | 博客
  • 博客访问: 128713
  • 博文数量: 16
  • 博客积分: 355
  • 博客等级: 一等列兵
  • 技术积分: 237
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-01 22:01
文章分类

全部博文(16)

文章存档

2012年(16)

我的朋友

分类: 嵌入式

2012-08-08 14:46:06



点击(此处)折叠或打开

  1. 要求静默升级的程序包名必须为com.dsplayer
  2. 1. android4.0/packages/apps/PackageInstaller/src/com/android/packageinstaller/InstallAppProgress.java
  3.     private Handler mHandler = new Handler() {
  4.             public void handleMessage(Message msg) {
  5.             ......
  6.             if (enabled) {
  7. +                if (mAppInfo.packageName.equals("com.dsplayer")) {
  8. +                    startActivity(mLaunchIntent);
  9. +                    finish();
  10. +                }

  11.                 mLaunchButton.setOnClickListener(InstallAppProgress.this);
  12.             } else {
  13.                 mLaunchButton.setEnabled(false);
  14.             }
  15.             ......
  16.         }
  17.     }

  18. 2. android4.0/packages/apps/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java

  19.     private void initiateInstall() {
  20.         String pkgName = mPkgInfo.packageName;
  21.         // Check if there is already a package on the device with this name

  22.         // but it has been renamed to something else.

  23.         String[] oldName = mPm.canonicalToCurrentPackageNames(new String[] { pkgName });
  24.         if (oldName != null && oldName.length > 0 && oldName[0] != null) {
  25.             pkgName = oldName[0];
  26.             mPkgInfo.setPackageName(pkgName);
  27.         }
  28.         // Check if package is already installed. display confirmation dialog if replacing pkg

  29.         try {
  30.             mAppInfo = mPm.getApplicationInfo(pkgName,
  31.                     PackageManager.GET_UNINSTALLED_PACKAGES);
  32.         } catch (NameNotFoundException e) {
  33.             mAppInfo = null;
  34.         }
  35.         
  36.     /*
  37.     if (mAppInfo == null || getIntent().getBooleanExtra(Intent.EXTRA_ALLOW_REPLACE, false)) {
  38.                       startInstallConfirm();
  39.         } else {
  40.                      if(localLOGV) Log.i(TAG, "Replacing existing package:"+
  41.                                 mPkgInfo.applicationInfo.packageName);
  42.                                 showDialogInner(DLG_REPLACE_APP);
  43.         }
  44.     */
  45.     // 注释上面程序,添加下面程序。

  46. +    if (pkgName.equals("com.dsplayer")) {
  47. +        startInstall();
  48. +    } else {
  49. +        if (mAppInfo == null || getIntent().getBooleanExtra(Intent.EXTRA_ALLOW_REPLACE, false)) {
  50. +            startInstallConfirm();
  51. +        } else {
  52. + if(localLOGV)
  53. +                Log.i(TAG, "Replacing existing package:"+ mPkgInfo.applicationInfo.packageName);
  54. +            showDialogInner(DLG_REPLACE_APP);
  55. +        }
  56. +    }
  57.     }

  58.      // 在文件最后添加下面函数。

  59. +    public void startInstall() {
  60. +        // Start subactivity to actually install the application

  61. +        Intent newIntent = new Intent();
  62. +        newIntent.putExtra(PackageUtil.INTENT_ATTR_APPLICATION_INFO,
  63. +                mPkgInfo.applicationInfo);
  64. +        newIntent.setData(mPackageURI);
  65. +        newIntent.setClass(this, InstallAppProgress.class);
  66. +        String installerPackageName = getIntent().getStringExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME);
  67. +        if (installerPackageName != null) {
  68. +            newIntent.putExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME, installerPackageName);
  69. +        }
  70. +        if(localLOGV)
  71. +            Log.i(TAG, "downloaded app uri="+mPackageURI);
  72. +        startActivity(newIntent);
  73. +        finish();
  74. +    }


阅读(10021) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~