本文整理汇总了Java中android.content.pm.PackageInstaller类的典型用法代码示例。如果您正苦于以下问题:Java PackageInstaller类的具体用法?Java PackageInstaller怎么用?Java PackageInstaller使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PackageInstaller类属于android.content.pm包,在下文中一共展示了PackageInstaller类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: installPackage
import android.content.pm.PackageInstaller; //导入依赖的package包/类
public static boolean installPackage(Context context, InputStream in, String packageName)
throws IOException {
PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller();
PackageInstaller.SessionParams params = new PackageInstaller.SessionParams(
PackageInstaller.SessionParams.MODE_FULL_INSTALL);
params.setAppPackageName(packageName);
// set params
int sessionId = packageInstaller.createSession(params);
PackageInstaller.Session session = packageInstaller.openSession(sessionId);
OutputStream out = session.openWrite("COSU", 0, -1);
byte[] buffer = new byte[65536];
int c;
while ((c = in.read(buffer)) != -1) {
out.write(buffer, 0, c);
}
session.fsync(out);
in.close();
out.close();
session.commit(createIntentSender(context, sessionId));
return true;
}
示例2: uninstall
import android.content.pm.PackageInstaller; //导入依赖的package包/类
@Override
public void uninstall(String packageName, String callerPackageName, int flags, IntentSender statusReceiver, int userId) throws RemoteException {
boolean success = VAppManagerService.get().uninstallPackage(packageName);
if (statusReceiver != null) {
final Intent fillIn = new Intent();
fillIn.putExtra(PackageInstaller.EXTRA_PACKAGE_NAME, packageName);
fillIn.putExtra(PackageInstaller.EXTRA_STATUS, success ? PackageInstaller.STATUS_SUCCESS : PackageInstaller.STATUS_FAILURE);
fillIn.putExtra(PackageInstaller.EXTRA_STATUS_MESSAGE, PackageHelper.deleteStatusToString(success));
fillIn.putExtra("android.content.pm.extra.LEGACY_STATUS", success ? 1 : -1);
try {
statusReceiver.sendIntent(mContext, 0, fillIn, null, null);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
}
}
示例3: onPackageInstalled
import android.content.pm.PackageInstaller; //导入依赖的package包/类
@Override
public void onPackageInstalled(String basePackageName, int returnCode, String msg,
Bundle extras) {
final Intent fillIn = new Intent();
fillIn.putExtra(PackageInstaller.EXTRA_PACKAGE_NAME, basePackageName);
fillIn.putExtra(PackageInstaller.EXTRA_SESSION_ID, mSessionId);
fillIn.putExtra(PackageInstaller.EXTRA_STATUS,
installStatusToPublicStatus(returnCode));
fillIn.putExtra(PackageInstaller.EXTRA_STATUS_MESSAGE,
installStatusToString(returnCode, msg));
fillIn.putExtra("android.content.pm.extra.LEGACY_STATUS", returnCode);
if (extras != null) {
final String existing = extras.getString("android.content.pm.extra.FAILURE_EXISTING_PACKAGE");
if (!TextUtils.isEmpty(existing)) {
fillIn.putExtra(PackageInstaller.EXTRA_OTHER_PACKAGE_NAME, existing);
}
}
try {
mTarget.sendIntent(mContext, 0, fillIn, null, null);
} catch (IntentSender.SendIntentException ignored) {
}
}
示例4: testPendingWidget_notRestored_activeInstall
import android.content.pm.PackageInstaller; //导入依赖的package包/类
public void testPendingWidget_notRestored_activeInstall() throws Exception {
// A widget which is being installed is not removed
LauncherAppWidgetInfo item = getInvalidWidgetInfo();
item.restoreStatus = LauncherAppWidgetInfo.FLAG_ID_NOT_VALID
| LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY;
// Create an active installer session
SessionParams params = new SessionParams(SessionParams.MODE_FULL_INSTALL);
params.setAppPackageName(item.providerName.getPackageName());
PackageInstaller installer = mTargetContext.getPackageManager().getPackageInstaller();
mSessionId = installer.createSession(params);
setupAndVerifyContents(item, PendingAppWidgetHostView.class, null);
// Verify item still exists in db
waitUntilLoaderIdle();
mCursor = mResolver.query(LauncherSettings.Favorites.getContentUri(item.id),
null, null, null, null, null);
assertEquals(1, mCursor.getCount());
// Widget still has an invalid id.
mCursor.moveToNext();
assertEquals(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID,
mCursor.getInt(mCursor.getColumnIndex(LauncherSettings.Favorites.RESTORED))
& LauncherAppWidgetInfo.FLAG_ID_NOT_VALID);
}
示例5: uninstall
import android.content.pm.PackageInstaller; //导入依赖的package包/类
@Override
public void uninstall(String packageName, String callerPackageName, int flags, IntentSender statusReceiver, int userId) throws RemoteException {
boolean success = VAppManagerService.get().uninstallApp(packageName);
if (statusReceiver != null) {
final Intent fillIn = new Intent();
fillIn.putExtra(PackageInstaller.EXTRA_PACKAGE_NAME, packageName);
fillIn.putExtra(PackageInstaller.EXTRA_STATUS, success ? PackageInstaller.STATUS_SUCCESS : PackageInstaller.STATUS_FAILURE);
fillIn.putExtra(PackageInstaller.EXTRA_STATUS_MESSAGE, PackageHelper.deleteStatusToString(success));
fillIn.putExtra("android.content.pm.extra.LEGACY_STATUS", success ? 1 : -1);
try {
statusReceiver.sendIntent(mContext, 0, fillIn, null, null);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
}
}
示例6: PackageInstallerImpl
import android.content.pm.PackageInstaller; //导入依赖的package包/类
public PackageInstallerImpl(Context paramContext)
{
this.mContext = paramContext;
this.mPackageInstaller = this.mContext.getPackageManager().getPackageInstaller();
this.mSessionInfoMap = new HashMap();
Iterator localIterator = this.mPackageInstaller.getMySessions().iterator();
while (localIterator.hasNext())
{
PackageInstaller.SessionInfo localSessionInfo1 = (PackageInstaller.SessionInfo)localIterator.next();
String str = localSessionInfo1.getAppPackageName();
PackageInstaller.SessionInfo localSessionInfo2 = (PackageInstaller.SessionInfo)this.mSessionInfoMap.put(str, localSessionInfo1);
if (localSessionInfo2 != null)
{
Object[] arrayOfObject = new Object[3];
arrayOfObject[0] = str;
arrayOfObject[1] = Integer.valueOf(localSessionInfo2.getSessionId());
arrayOfObject[2] = Integer.valueOf(localSessionInfo1.getSessionId());
FinskyLog.w("Multiple sessions for %s found. Removing %d & keeping %d.", arrayOfObject);
}
}
this.mOpenSessionMap = new HashMap();
}
示例7: a
import android.content.pm.PackageInstaller; //导入依赖的package包/类
private static boolean a(Context paramContext, String paramString)
{
if (Build.VERSION.SDK_INT >= 21) {}
for (int i = 1; i != 0; i = 0)
{
Iterator localIterator = paramContext.getPackageManager().getPackageInstaller().getAllSessions().iterator();
do
{
if (!localIterator.hasNext()) {
break;
}
} while (!paramString.equals(((PackageInstaller.SessionInfo)localIterator.next()).getAppPackageName()));
return true;
}
PackageManager localPackageManager = paramContext.getPackageManager();
try
{
boolean bool = localPackageManager.getApplicationInfo(paramString, 8192).enabled;
if (bool) {
return true;
}
}
catch (PackageManager.NameNotFoundException localNameNotFoundException) {}
return false;
}
示例8: onUserActionRequired
import android.content.pm.PackageInstaller; //导入依赖的package包/类
@Override
public void onUserActionRequired(Intent intent) {
final Intent fillIn = new Intent();
fillIn.putExtra(PackageInstaller.EXTRA_SESSION_ID, mSessionId);
fillIn.putExtra(PackageInstaller.EXTRA_STATUS,
PackageInstaller.STATUS_PENDING_USER_ACTION);
fillIn.putExtra(Intent.EXTRA_INTENT, intent);
try {
mTarget.sendIntent(mContext, 0, fillIn, null, null);
} catch (IntentSender.SendIntentException ignored) {
}
}
示例9: getStream
import android.content.pm.PackageInstaller; //导入依赖的package包/类
public final OutputStream getStream(String paramString1, String paramString2, long paramLong)
throws IOException
{
PackageInstaller.Session localSession = getSession(paramString1);
if (localSession == null)
{
FinskyLog.e("Can't open session for %s", new Object[] { paramString1 });
throw new IOException();
}
return new SessionStreamWrapper(localSession.openWrite(paramString2, 0L, paramLong), localSession);
}
示例10: onReceive
import android.content.pm.PackageInstaller; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
if (!CosuUtils.ACTION_INSTALL_COMPLETE.equals(intent.getAction())) {
return;
}
int result = intent.getIntExtra(PackageInstaller.EXTRA_STATUS,
PackageInstaller.STATUS_FAILURE);
String packageName = intent.getStringExtra(PackageInstaller.EXTRA_PACKAGE_NAME);
if (CosuUtils.DEBUG) Log.d(CosuUtils.TAG, "PackageInstallerCallback: result=" + result
+ " packageName=" + packageName);
switch (result) {
case PackageInstaller.STATUS_PENDING_USER_ACTION: {
// this should not happen in M, but will happen in L and L-MR1
startActivity((Intent) intent.getParcelableExtra(Intent.EXTRA_INTENT));
} break;
case PackageInstaller.STATUS_SUCCESS: {
mHandler.sendMessage(mHandler.obtainMessage(CosuUtils.MSG_INSTALL_COMPLETE,
packageName));
} break;
default: {
Log.e(CosuUtils.TAG, "Install failed.");
finishWithFailure();
return;
}
}
}
示例11: getPackageInstaller
import android.content.pm.PackageInstaller; //导入依赖的package包/类
@RequiresApi(LOLLIPOP) @Override @NonNull public PackageInstaller getPackageInstaller() {
return mBase.getPackageInstaller();
}
示例12: getPackageInstaller
import android.content.pm.PackageInstaller; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public PackageInstaller getPackageInstaller() {
return this.mHostPackageManager.getPackageInstaller();
}
示例13: getPackageInstaller
import android.content.pm.PackageInstaller; //导入依赖的package包/类
@RequiresApi(LOLLIPOP) public @NonNull PackageInstaller getPackageInstaller() {
throw new UnsupportedOperationException("PackageManager.getPackageInstaller() is not yet supported by Project Condom. " +
"If it causes trouble, please file an issue on GitHub.");
}
示例14: installStatusToPublicStatus
import android.content.pm.PackageInstaller; //导入依赖的package包/类
/** {@hide} */
public static int installStatusToPublicStatus(int status) {
switch (status) {
case INSTALL_SUCCEEDED: return PackageInstaller.STATUS_SUCCESS;
case INSTALL_FAILED_ALREADY_EXISTS: return PackageInstaller.STATUS_FAILURE_CONFLICT;
case INSTALL_FAILED_INVALID_APK: return PackageInstaller.STATUS_FAILURE_INVALID;
case INSTALL_FAILED_INVALID_URI: return PackageInstaller.STATUS_FAILURE_INVALID;
case INSTALL_FAILED_INSUFFICIENT_STORAGE: return PackageInstaller.STATUS_FAILURE_STORAGE;
case INSTALL_FAILED_DUPLICATE_PACKAGE: return PackageInstaller.STATUS_FAILURE_CONFLICT;
case INSTALL_FAILED_NO_SHARED_USER: return PackageInstaller.STATUS_FAILURE_CONFLICT;
case INSTALL_FAILED_UPDATE_INCOMPATIBLE: return PackageInstaller.STATUS_FAILURE_CONFLICT;
case INSTALL_FAILED_SHARED_USER_INCOMPATIBLE: return PackageInstaller.STATUS_FAILURE_CONFLICT;
case INSTALL_FAILED_MISSING_SHARED_LIBRARY: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
case INSTALL_FAILED_REPLACE_COULDNT_DELETE: return PackageInstaller.STATUS_FAILURE_CONFLICT;
case INSTALL_FAILED_DEXOPT: return PackageInstaller.STATUS_FAILURE_INVALID;
case INSTALL_FAILED_OLDER_SDK: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
case INSTALL_FAILED_CONFLICTING_PROVIDER: return PackageInstaller.STATUS_FAILURE_CONFLICT;
case INSTALL_FAILED_NEWER_SDK: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
case INSTALL_FAILED_TEST_ONLY: return PackageInstaller.STATUS_FAILURE_INVALID;
case INSTALL_FAILED_CPU_ABI_INCOMPATIBLE: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
case INSTALL_FAILED_MISSING_FEATURE: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
case INSTALL_FAILED_CONTAINER_ERROR: return PackageInstaller.STATUS_FAILURE_STORAGE;
case INSTALL_FAILED_INVALID_INSTALL_LOCATION: return PackageInstaller.STATUS_FAILURE_STORAGE;
case INSTALL_FAILED_MEDIA_UNAVAILABLE: return PackageInstaller.STATUS_FAILURE_STORAGE;
case INSTALL_FAILED_VERIFICATION_TIMEOUT: return PackageInstaller.STATUS_FAILURE_ABORTED;
case INSTALL_FAILED_VERIFICATION_FAILURE: return PackageInstaller.STATUS_FAILURE_ABORTED;
case INSTALL_FAILED_PACKAGE_CHANGED: return PackageInstaller.STATUS_FAILURE_INVALID;
case INSTALL_FAILED_UID_CHANGED: return PackageInstaller.STATUS_FAILURE_INVALID;
case INSTALL_FAILED_VERSION_DOWNGRADE: return PackageInstaller.STATUS_FAILURE_INVALID;
case INSTALL_FAILED_PERMISSION_MODEL_DOWNGRADE: return PackageInstaller.STATUS_FAILURE_INVALID;
case INSTALL_PARSE_FAILED_NOT_APK: return PackageInstaller.STATUS_FAILURE_INVALID;
case INSTALL_PARSE_FAILED_BAD_MANIFEST: return PackageInstaller.STATUS_FAILURE_INVALID;
case INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION: return PackageInstaller.STATUS_FAILURE_INVALID;
case INSTALL_PARSE_FAILED_NO_CERTIFICATES: return PackageInstaller.STATUS_FAILURE_INVALID;
case INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES: return PackageInstaller.STATUS_FAILURE_INVALID;
case INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING: return PackageInstaller.STATUS_FAILURE_INVALID;
case INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME: return PackageInstaller.STATUS_FAILURE_INVALID;
case INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID: return PackageInstaller.STATUS_FAILURE_INVALID;
case INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: return PackageInstaller.STATUS_FAILURE_INVALID;
case INSTALL_PARSE_FAILED_MANIFEST_EMPTY: return PackageInstaller.STATUS_FAILURE_INVALID;
case INSTALL_FAILED_INTERNAL_ERROR: return PackageInstaller.STATUS_FAILURE;
case INSTALL_FAILED_USER_RESTRICTED: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
case INSTALL_FAILED_DUPLICATE_PERMISSION: return PackageInstaller.STATUS_FAILURE_CONFLICT;
case INSTALL_FAILED_NO_MATCHING_ABIS: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
case INSTALL_FAILED_ABORTED: return PackageInstaller.STATUS_FAILURE_ABORTED;
default: return PackageInstaller.STATUS_FAILURE;
}
}
示例15: getPackageInstaller
import android.content.pm.PackageInstaller; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@NonNull
@Override
public PackageInstaller getPackageInstaller() {
return mBase.getPackageInstaller();
}