当前位置: 首页>>代码示例>>Java>>正文


Java PackageInstaller.createSession方法代码示例

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


在下文中一共展示了PackageInstaller.createSession方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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


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