Java Code Examples for android.content.pm.PackageInstaller#createSession()
The following examples show how to use
android.content.pm.PackageInstaller#createSession() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DummyActivity.java From Shelter with Do What The F*ck You Want To Public License | 6 votes |
private void actionInstallPackageQ(Uri uri) throws IOException { PackageInstaller pi = getPackageManager().getPackageInstaller(); PackageInstaller.SessionParams params = new PackageInstaller.SessionParams( PackageInstaller.SessionParams.MODE_FULL_INSTALL); int sessionId = pi.createSession(params); // Show the progress dialog first pi.registerSessionCallback(new InstallationProgressListener(this, pi, sessionId)); PackageInstaller.Session session = pi.openSession(sessionId); doInstallPackageQ(uri, session, () -> { // We have finished piping the streams, show the progress as 10% session.setStagingProgress(0.1f); // Commit the session Intent intent = new Intent(this, DummyActivity.class); intent.setAction(PACKAGEINSTALLER_CALLBACK); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); session.commit(pendingIntent.getIntentSender()); }); }
Example 2
Source File: InstallerPrivilegedSession.java From YalpStore with GNU General Public License v2.0 | 6 votes |
@Override protected void install(App app) { registerReceiver(); PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller(); PackageInstaller.SessionParams sessionParams = new PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL); sessionParams.setAppPackageName(app.getPackageName()); sessionParams.setAppLabel(app.getDisplayName()); PackageInstaller.Session session = null; try { int sessionId = packageInstaller.createSession(sessionParams); session = packageInstaller.openSession(sessionId); for (File file: Paths.getApkAndSplits(context, app.getPackageName(), app.getVersionCode())) { writeFileToSession(file, session); } session.commit(getIntentSender(sessionId)); } catch (IOException e) { fail(e, app.getPackageName()); } finally { com.github.yeriomin.yalpstore.Util.closeSilently(session); } }
Example 3
Source File: VersionFixer.java From xDrip with GNU General Public License v3.0 | 6 votes |
private static boolean installPackage(Context context, InputStream in, String packageName) throws IOException { final PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller(); final PackageInstaller.SessionParams params = new PackageInstaller.SessionParams( PackageInstaller.SessionParams.MODE_FULL_INSTALL); params.setAppPackageName(packageName); final int sessionId = packageInstaller.createSession(params); final PackageInstaller.Session session = packageInstaller.openSession(sessionId); final OutputStream out = session.openWrite("COSU", 0, -1); final byte[] buffer = new byte[65536]; int bytes_read; while ((bytes_read = in.read(buffer)) != -1) { out.write(buffer, 0, bytes_read); } session.fsync(out); in.close(); out.close(); session.commit(createIntentSender(context, sessionId)); return true; }
Example 4
Source File: VersionFixer.java From xDrip with GNU General Public License v3.0 | 6 votes |
private static boolean installPackage(Context context, byte[] buffer, String packageName) throws IOException { final PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller(); final PackageInstaller.SessionParams params = new PackageInstaller.SessionParams( PackageInstaller.SessionParams.MODE_FULL_INSTALL); params.setAppPackageName(packageName); final int sessionId = packageInstaller.createSession(params); final PackageInstaller.Session session = packageInstaller.openSession(sessionId); final OutputStream out = session.openWrite("COSU", 0, -1); out.write(buffer, 0, buffer.length); session.fsync(out); out.close(); session.commit(createIntentSender(context, sessionId)); return true; }
Example 5
Source File: VersionFixer.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
private static boolean installPackage(Context context, InputStream in, String packageName) throws IOException { final PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller(); final PackageInstaller.SessionParams params = new PackageInstaller.SessionParams( PackageInstaller.SessionParams.MODE_FULL_INSTALL); params.setAppPackageName(packageName); final int sessionId = packageInstaller.createSession(params); final PackageInstaller.Session session = packageInstaller.openSession(sessionId); final OutputStream out = session.openWrite("COSU", 0, -1); final byte[] buffer = new byte[65536]; int bytes_read; while ((bytes_read = in.read(buffer)) != -1) { out.write(buffer, 0, bytes_read); } session.fsync(out); in.close(); out.close(); session.commit(createIntentSender(context, sessionId)); return true; }
Example 6
Source File: VersionFixer.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
private static boolean installPackage(Context context, byte[] buffer, String packageName) throws IOException { final PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller(); final PackageInstaller.SessionParams params = new PackageInstaller.SessionParams( PackageInstaller.SessionParams.MODE_FULL_INSTALL); params.setAppPackageName(packageName); final int sessionId = packageInstaller.createSession(params); final PackageInstaller.Session session = packageInstaller.openSession(sessionId); final OutputStream out = session.openWrite("COSU", 0, -1); out.write(buffer, 0, buffer.length); session.fsync(out); out.close(); session.commit(createIntentSender(context, sessionId)); return true; }
Example 7
Source File: PackageInstallationUtils.java From android-testdpc with Apache License 2.0 | 6 votes |
public static boolean installPackage(Context context, InputStream in, String packageName) throws IOException { final PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller(); final PackageInstaller.SessionParams params = new PackageInstaller.SessionParams( PackageInstaller.SessionParams.MODE_FULL_INSTALL); params.setAppPackageName(packageName); // set params final int sessionId = packageInstaller.createSession(params); final PackageInstaller.Session session = packageInstaller.openSession(sessionId); final OutputStream out = session.openWrite("TestDPC", 0, -1); final 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(createInstallIntentSender(context, sessionId)); return true; }
Example 8
Source File: InstallActivity.java From XAPKInstaller with Apache License 2.0 | 5 votes |
@TargetApi(21) private PackageInstaller.Session initSession() throws IOException { PackageInstaller.Session session = null; PackageInstaller packageInstaller = getPackageManager().getPackageInstaller(); PackageInstaller.SessionParams params = new PackageInstaller.SessionParams( PackageInstaller.SessionParams.MODE_FULL_INSTALL); int sessionId = 0; sessionId = packageInstaller.createSession(params); session = packageInstaller.openSession(sessionId); return session; }