资源简介

近日想实现静默安装(不提示用户),网上搜文章大多提到一个方法 PackageManager.install,这是个非公开方法,它的用法是借鉴了内置应用 packageInstaller,跳过Activity提示用户,直接调用核心方法。用Git下载Android源码较麻烦,也很大,特把这一部分的源码打包给大家。

资源截图

代码片段和文件信息

/*
**
** Copyright 2007 The Android Open Source Project
**
** Licensed under the Apache License Version 2.0 (the “License“);
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing software
** distributed under the License is distributed on an “AS IS“ BASIS
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
package com.android.packageinstaller;

import com.android.packageinstaller.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnCancelListener;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageInstallObserver;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.drawable.LevelListDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

import java.util.List;

/**
 * This activity corresponds to a download progress screen that is displayed 
 * when the user tries
 * to install an application bundled as an apk file. The result of the application install
 * is indicated in the result code that gets set to the corresponding installation status
 * codes defined in PackageManager. If the package being installed already exists
 * the existing package is replaced with the new one.
 */
public class InstallAppProgress extends Activity implements View.onclickListener OnCancelListener {
    private final String TAG=“InstallAppProgress“;
    private boolean localLOGV = false;
    private ApplicationInfo mAppInfo;
    private Uri mPackageURI;
    private ProgressBar mProgressBar;
    private View mOkPanel;
    private TextView mStatusTextView;
    private TextView mExplanationTextView;
    private Button mDoneButton;
    private Button mLaunchButton;
    private final int INSTALL_COMPLETE = 1;
    private Intent mLaunchIntent;
    private static final int DLG_OUT_OF_SPACE = 1;
    private CharSequence mLabel;

    private Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case INSTALL_COMPLETE:
                    if (getIntent().getBooleanExtra(Intent.EXTRA_RETURN_RESULT false)) {
                        Intent result = new Intent();
                        result.putExtra(Intent.EXTRA_INSTALL_RESULT msg.arg1);
                        setRe

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\
     文件         227  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\Android.mk
     文件        2949  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\AndroidManifest.xml
     文件        2227  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\CleanSpec.mk
     文件           0  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\MODULE_LICENSE_APACHE2
     文件       10695  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\NOTICE
     目录           0  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\
     目录           0  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\drawable-hdpi\
     文件         707  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\drawable-hdpi\ic_fail.png
     文件         651  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\drawable-hdpi\ic_success.png
     目录           0  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\drawable-mdpi\
     文件         594  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\drawable-mdpi\ic_fail.png
     文件         505  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\drawable-mdpi\ic_success.png
     目录           0  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\drawable-xhdpi\
     文件         947  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\drawable-xhdpi\ic_fail.png
     文件         820  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\drawable-xhdpi\ic_success.png
     目录           0  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\drawable\
     文件         952  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\drawable\ic_result_status.xml
     目录           0  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\layout\
     文件        2595  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\layout\app_details.xml
     文件        5053  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\layout\install_confirm.xml
     文件        1325  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\layout\install_start.xml
     文件        4632  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\layout\op_progress.xml
     文件        4532  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\layout\uninstall_confirm.xml
     文件        4532  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\layout\uninstall_progress.xml
     目录           0  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\values-af\
     文件        7234  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\values-af\strings.xml
     目录           0  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\values-am\
     文件        7884  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\values-am\strings.xml
     目录           0  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\values-ar\
     文件        8022  2011-12-06 10:29  android-platform_packages_apps_packageinstaller-668cc01\res\values-ar\strings.xml
............此处省略106个文件信息

评论

共有 条评论