• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java PackageInstaller类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中android.content.pm.PackageInstaller的典型用法代码示例。如果您正苦于以下问题:Java PackageInstaller类的具体用法?Java PackageInstaller怎么用?Java PackageInstaller使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PackageInstaller类属于android.content.pm包,在下文中一共展示了PackageInstaller类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
 
开发者ID:googlesamples,项目名称:android-testdpc,代码行数:23,代码来源:CosuUtils.java


示例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();
        }
    }
}
 
开发者ID:7763sea,项目名称:VirtualHook,代码行数:17,代码来源:VPackageInstallerService.java


示例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) {
    }
}
 
开发者ID:7763sea,项目名称:VirtualHook,代码行数:23,代码来源:VPackageInstallerService.java


示例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);
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:26,代码来源:BindWidgetTest.java


示例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();
        }
    }
}
 
开发者ID:codehz,项目名称:container,代码行数:17,代码来源:VPackageInstallerService.java


示例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();
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:23,代码来源:PackageInstallerImpl.java


示例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;
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:26,代码来源:eer.java


示例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) {
    }
}
 
开发者ID:7763sea,项目名称:VirtualHook,代码行数:13,代码来源:VPackageInstallerService.java


示例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);
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:12,代码来源:PackageInstallerImpl.java


示例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;
        }
    }
}
 
开发者ID:googlesamples,项目名称:android-testdpc,代码行数:28,代码来源:EnableCosuActivity.java


示例11: getPackageInstaller

import android.content.pm.PackageInstaller; //导入依赖的package包/类
@RequiresApi(LOLLIPOP) @Override @NonNull public PackageInstaller getPackageInstaller() {
	return mBase.getPackageInstaller();
}
 
开发者ID:Trumeet,项目名称:MiPushFramework,代码行数:4,代码来源:PackageManagerWrapper.java


示例12: getPackageInstaller

import android.content.pm.PackageInstaller; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public PackageInstaller getPackageInstaller() {
    return this.mHostPackageManager.getPackageInstaller();
}
 
开发者ID:didi,项目名称:VirtualAPK,代码行数:6,代码来源:LoadedPlugin.java


示例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.");
}
 
开发者ID:oasisfeng,项目名称:condom,代码行数:5,代码来源:CondomPackageManager.java


示例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;
    }
}
 
开发者ID:7763sea,项目名称:VirtualHook,代码行数:49,代码来源:PackageHelper.java


示例15: getPackageInstaller

import android.content.pm.PackageInstaller; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@NonNull
@Override
public PackageInstaller getPackageInstaller() {
    return mBase.getPackageInstaller();
}
 
开发者ID:xyxyLiu,项目名称:PluginM,代码行数:7,代码来源:PluginPackageManager.java


示例16: zzi

import android.content.pm.PackageInstaller; //导入依赖的package包/类
static boolean zzi(Context paramContext, String paramString)
{
  boolean bool1 = true;
  if (zzq.zzdC(21))
  {
    Iterator localIterator = paramContext.getPackageManager().getPackageInstaller().getAllSessions().iterator();
    while (localIterator.hasNext()) {
      if (paramString.equals(((PackageInstaller.SessionInfo)localIterator.next()).getAppPackageName())) {
        return bool1;
      }
    }
  }
  if (zzq.zzdC(18))
  {
    Bundle localBundle = ((UserManager)paramContext.getSystemService("user")).getApplicationRestrictions(paramContext.getPackageName());
    if ((localBundle == null) || (!"true".equals(localBundle.getString("restricted_profile")))) {}
  }
  while (bool1)
  {
    return false;
    bool1 = false;
  }
  PackageManager localPackageManager = paramContext.getPackageManager();
  try
  {
    boolean bool2 = localPackageManager.getApplicationInfo(paramString, 8192).enabled;
    return bool2;
  }
  catch (PackageManager.NameNotFoundException localNameNotFoundException) {}
  return false;
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:32,代码来源:GooglePlayServicesUtil.java


示例17: SessionStreamWrapper

import android.content.pm.PackageInstaller; //导入依赖的package包/类
public SessionStreamWrapper(OutputStream paramOutputStream, PackageInstaller.Session paramSession)
{
  super();
  this.stream = paramOutputStream;
  this.session = paramSession;
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:7,代码来源:PackageInstallerImpl.java


示例18: getPackageInstaller

import android.content.pm.PackageInstaller; //导入依赖的package包/类
@Override
public PackageInstaller getPackageInstaller() {
    return packageManager.getPackageInstaller();
}
 
开发者ID:KsyMC,项目名称:ForgePE,代码行数:5,代码来源:CustomPackageManager.java


示例19: getPackageInstaller

import android.content.pm.PackageInstaller; //导入依赖的package包/类
@Override
public PackageInstaller getPackageInstaller() {
	return mProxy.getPackageInstaller();
}
 
开发者ID:luoqii,项目名称:ApkLauncher,代码行数:5,代码来源:PackageManagerProxy.java


示例20: getPackageInstaller

import android.content.pm.PackageInstaller; //导入依赖的package包/类
@Override
public PackageInstaller getPackageInstaller() {
	notSupported();
	return null;
}
 
开发者ID:luoqii,项目名称:ApkLauncher,代码行数:6,代码来源:BasePackageManager.java



注:本文中的android.content.pm.PackageInstaller类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OFPacketOut类代码示例发布时间:2022-05-21
下一篇:
Java MultiSearchRequest类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap