/*
**
** 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 android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PackageParser;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AppSecurityPermissions;
import android.widget.Button;
import android.widget.LinearLayout;
/*
* This activity is launched when a new application is installed via side loading
* The package is first parsed and the user is notified of parse errors via a dialog.
* If the package is successfully parsed, the user is notified to turn on the install unknown
* applications setting. A memory check is made at this point and the user is notified of out
* of memory conditions if any. If the package is already existing on the device,
* a confirmation dialog (to replace the existing package) is presented to the user.
* Based on the user response the package is then installed by launching InstallAppConfirm
* sub activity. All state transitions are handled in this activity
*/
public class PackageInstallerActivity extends Activity implements OnCancelListener, OnClickListener {
private static final String TAG = "PackageInstaller";
private Uri mPackageURI;
private boolean localLOGV = false;
PackageManager mPm;
PackageParser.Package mPkgInfo;
ApplicationInfo mSourceInfo;
// ApplicationInfo object primarily used for already existing applications
private ApplicationInfo mAppInfo = null;
// View for install progress
View mInstallConfirm;
// Buttons to indicate user acceptance
private Button mOk;
private Button mCancel;
static final String PREFS_ALLOWED_SOURCES = "allowed_sources";
// Dialog identifiers used in showDialog
private static final int DLG_BASE = 0;
private static final int DLG_REPLACE_APP = DLG_BASE + 1;
private static final int DLG_UNKNOWN_APPS = DLG_BASE + 2;
private static final int DLG_PACKAGE_ERROR = DLG_BASE + 3;
private static final int DLG_OUT_OF_SPACE = DLG_BASE + 4;
private static final int DLG_INSTALL_ERROR = DLG_BASE + 5;
private static final int DLG_ALLOW_SOURCE = DLG_BASE + 6;
private void startInstallConfirm() {
LinearLayout permsSection = (LinearLayout) mInstallConfirm.findViewById(R.id.permissions_section);
LinearLayout securityList = (LinearLayout) permsSection.findViewById(
R.id.security_settings_list);
boolean permVisible = false;
if(mPkgInfo != null) {
AppSecurityPermissions asp = new AppSecurityPermissions(this, mPkgInfo);
if(asp.getPermissionCount() > 0) {
permVisible = true;
securityList.addView(asp.getPermissionsView());
}
}
if(!permVisible){
permsSection.setVisibility(View.INVISIBLE);
}
mInstallConfirm.setVisibility(View.VISIBLE);
mOk = (Button)findViewById(R.id.ok_button);
mCancel = (Button)findViewById(R.id.cancel_button);
mOk.setOnClickListener(this);
mCancel.setOnClickListener(this);
}
private void showDialogInner(int id) {
// TODO better fix for this? Remove dialog so that it gets created again
removeDialog(id);
showDialog(id);
}
@Override
public Dialog onCreateDialog(int id, Bundle bundle) {
switch (id) {
case DLG_REPLACE_APP:
int msgId = R.string.dlg_app_replacement_statement;
// Customized text for system apps
if ((mAppInfo != null) && (mAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
msgId = R.string.dlg_sys_app_replacement_statement;
}
return new AlertDialog.Builder(this)
.setTitle(R.string.dlg_app_replacement_title)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
startInstallConfirm();
}})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Log.i(TAG, "Canceling installation");
setResult(RESULT_CANCELED);
finish();
}})
.setMessage(msgId)
.setOnCancelListener(this)
.create();
case DLG_UNKNOWN_APPS:
return new AlertDialog.Builder(this)
.setTitle(R.string.unknown_apps_dlg_title)
.setMessage(R.string.unknown_apps_dlg_text)
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Log.i(TAG, "Finishing off activity so that user can navigate to settings manually");
finish();
}})
.setPositiveButton(R.string.settings, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Log.i(TAG, "Launching settings");
launchSettingsAppAndFinish();
}
})
.setOnCancelListener(this)
.create();
case DLG_PACKAGE_ERROR :
return new AlertDialog.Builder(this)
.setTitle(R.string.Parse_error_dlg_title)
.setMessage(R.string.Parse_error_dlg_text)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.setOnCancelListener(this)
.create();
case DLG_OUT_OF_SPACE:
// Guaranteed not to be null. will default to package name if not set by app
CharSequence appTitle = mPm.getApplicationLabel(mPkgInfo.applicationInfo);
String dlgText = getString(R.string.out_of_space_dlg_text,
appTitle.toString());
return new AlertDialog.Builder(this)
.setTitle(R.string.out_of_space_dlg_title)
.setMessage(dlgText)
.setPositiveButton(R.string.manage_applications, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//launch manage applications
Intent intent = new Intent("android.intent.action.MANAGE_PACKAGE_STORAGE");
没有合适的资源?快使用搜索试试~ 我知道了~
Android Package Installer 源代码(静默安装参考)
共76个文件
xml:60个
java:6个
png:6个
4星 · 超过85%的资源 需积分: 44 300 下载量 119 浏览量
2012-03-16
10:10:20
上传
评论 4
收藏 194KB ZIP 举报
温馨提示
近日想实现静默安装(不提示用户),网上搜文章大多提到一个方法 PackageManager.install,这是个非公开方法,它的用法是借鉴了内置应用 packageInstaller,跳过Activity提示用户,直接调用核心方法。用Git下载Android源码较麻烦,也很大,特把这一部分的源码打包给大家。
资源推荐
资源详情
资源评论
收起资源包目录
packages_apps_packageinstaller.zip (76个子文件)
android-platform_packages_apps_packageinstaller-668cc01
AndroidManifest.xml 3KB
res
values-lv
strings.xml 7KB
values-el
strings.xml 9KB
values-sr
strings.xml 9KB
values-tl
strings.xml 7KB
values-sl
strings.xml 7KB
values-sv
strings.xml 7KB
values-sk
strings.xml 7KB
values-es-rUS
strings.xml 7KB
values-iw
strings.xml 7KB
layout
install_start.xml 1KB
uninstall_confirm.xml 4KB
op_progress.xml 5KB
install_confirm.xml 5KB
app_details.xml 3KB
uninstall_progress.xml 4KB
values-th
strings.xml 10KB
values-fr
strings.xml 7KB
values-zh-rTW
strings.xml 7KB
values-nl
strings.xml 7KB
values-cs
strings.xml 7KB
values-vi
strings.xml 8KB
values-hi
strings.xml 10KB
values-hr
strings.xml 7KB
values-af
strings.xml 7KB
values-ms
strings.xml 7KB
values-uk
strings.xml 8KB
values-be
strings.xml 9KB
values-ko
strings.xml 8KB
drawable
ic_result_status.xml 952B
drawable-mdpi
ic_success.png 505B
ic_fail.png 594B
values-ja
strings.xml 8KB
values-it
strings.xml 7KB
values-pl
strings.xml 7KB
values-en-rGB
strings.xml 7KB
values-pt-rPT
strings.xml 7KB
values-ar
strings.xml 8KB
values-nb
strings.xml 7KB
values-in
strings.xml 7KB
values-hu
strings.xml 7KB
values-tr
strings.xml 7KB
values-et
strings.xml 7KB
values-am
strings.xml 8KB
values-ru
strings.xml 9KB
drawable-hdpi
ic_success.png 651B
ic_fail.png 707B
drawable-xhdpi
ic_success.png 820B
ic_fail.png 947B
values-es
strings.xml 7KB
values-zh-rCN
strings.xml 7KB
values-de
strings.xml 7KB
values-sw
strings.xml 7KB
values-ro
strings.xml 7KB
values-bg
strings.xml 9KB
values-rm
strings.xml 7KB
values
strings.xml 8KB
colors.xml 792B
styles.xml 844B
values-fa
strings.xml 8KB
values-da
strings.xml 7KB
values-pt
strings.xml 7KB
values-fi
strings.xml 7KB
values-lt
strings.xml 7KB
values-zu
strings.xml 7KB
values-ca
strings.xml 7KB
src
com
android
packageinstaller
UninstallerActivity.java 8KB
UninstallAppProgress.java 7KB
RemoveReceiver.java 1KB
InstallAppProgress.java 11KB
PackageUtil.java 7KB
PackageInstallerActivity.java 16KB
CleanSpec.mk 2KB
NOTICE 10KB
MODULE_LICENSE_APACHE2 0B
Android.mk 227B
共 76 条
- 1
RicherZ
- 粉丝: 4
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- DatabaseWatermarkingBasedonTextFormat
- -移动通信-网络课程设计与研究
- 基于Python的PCA人脸识别算法的原理及实现代码+文档详解.zip
- 甘肃移动全业务工程建设项目管理流程优化研究
- 549springboot + vue 民宿管理平台.zip (可运行源码+数据库文件+文档)
- ZArchiver.Pro_0.9.5.apk
- vmware环境配置.mp4
- 548springboot + vue 大学生社团活动平台.zip(可运行源码+数据库文件+文档)
- 微信小程序 辩论倒计时小程序源码 作业设计demo 计算机专业参考
- 深入探究文件IO,嵌入式Linux
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页