- 要求静默升级的程序包名必须为com.dsplayer
- 1. android4.0/packages/apps/PackageInstaller/src/com/android/packageinstaller/InstallAppProgress.java
- private Handler mHandler = new Handler() {
- public void handleMessage(Message msg) {
- ......
- if (enabled) {
- + if (mAppInfo.packageName.equals("com.dsplayer")) {
- + startActivity(mLaunchIntent);
- + finish();
- + }
- mLaunchButton.setOnClickListener(InstallAppProgress.this);
- } else {
- mLaunchButton.setEnabled(false);
- }
- ......
- }
- }
- 2. android4.0/packages/apps/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java
- private void initiateInstall() {
- String pkgName = mPkgInfo.packageName;
- // Check if there is already a package on the device with this name
- // but it has been renamed to something else.
- String[] oldName = mPm.canonicalToCurrentPackageNames(new String[] { pkgName });
- if (oldName != null && oldName.length > 0 && oldName[0] != null) {
- pkgName = oldName[0];
- mPkgInfo.setPackageName(pkgName);
- }
- // Check if package is already installed. display confirmation dialog if replacing pkg
- try {
- mAppInfo = mPm.getApplicationInfo(pkgName,
- PackageManager.GET_UNINSTALLED_PACKAGES);
- } catch (NameNotFoundException e) {
- mAppInfo = null;
- }
-
- /*
- if (mAppInfo == null || getIntent().getBooleanExtra(Intent.EXTRA_ALLOW_REPLACE, false)) {
- startInstallConfirm();
- } else {
- if(localLOGV) Log.i(TAG, "Replacing existing package:"+
- mPkgInfo.applicationInfo.packageName);
- showDialogInner(DLG_REPLACE_APP);
- }
- */
- // 注释上面程序,添加下面程序。
- + if (pkgName.equals("com.dsplayer")) {
- + startInstall();
- + } else {
- + if (mAppInfo == null || getIntent().getBooleanExtra(Intent.EXTRA_ALLOW_REPLACE, false)) {
- + startInstallConfirm();
- + } else {
- + if(localLOGV)
- + Log.i(TAG, "Replacing existing package:"+ mPkgInfo.applicationInfo.packageName);
- + showDialogInner(DLG_REPLACE_APP);
- + }
- + }
- }
- // 在文件最后添加下面函数。
- + public void startInstall() {
- + // Start subactivity to actually install the application
- + Intent newIntent = new Intent();
- + newIntent.putExtra(PackageUtil.INTENT_ATTR_APPLICATION_INFO,
- + mPkgInfo.applicationInfo);
- + newIntent.setData(mPackageURI);
- + newIntent.setClass(this, InstallAppProgress.class);
- + String installerPackageName = getIntent().getStringExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME);
- + if (installerPackageName != null) {
- + newIntent.putExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME, installerPackageName);
- + }
- + if(localLOGV)
- + Log.i(TAG, "downloaded app uri="+mPackageURI);
- + startActivity(newIntent);
- + finish();
- + }
阅读(10021) | 评论(0) | 转发(0) |