Java Code Examples for android.content.Intent#ACTION_INSTALL_PACKAGE

The following examples show how to use android.content.Intent#ACTION_INSTALL_PACKAGE . 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: UpdateApkReadyListener.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private void displayInstallNotification(Context context, Uri uri) {
  Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
  intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  intent.setData(uri);

  PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

  Notification notification = new NotificationCompat.Builder(context, NotificationChannels.APP_UPDATES)
      .setOngoing(true)
      .setContentTitle(context.getString(R.string.UpdateApkReadyListener_Signal_update))
      .setContentText(context.getString(R.string.UpdateApkReadyListener_a_new_version_of_signal_is_available_tap_to_update))
      .setSmallIcon(R.drawable.ic_notification)
      .setColor(context.getResources().getColor(R.color.core_ultramarine))
      .setPriority(NotificationCompat.PRIORITY_HIGH)
      .setCategory(NotificationCompat.CATEGORY_REMINDER)
      .setContentIntent(pendingIntent)
      .build();

  ServiceUtil.getNotificationManager(context).notify(666, notification);
}
 
Example 2
Source File: YTutils.java    From YTPlayer with GNU General Public License v3.0 6 votes vote down vote up
void runInstall(Context context, String updateName) {
    File f = getFile(Environment.DIRECTORY_DOWNLOADS + "/" + updateName);
    Uri data = Uri.fromFile(f);
    Log.e(TAG, "runInstall: Uri of FIle: " + data.toString());
    if (f.exists()) {

        Uri uri = getApkUri(f.getPath());

        Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
        intent.setData(uri);
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
        intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
        intent.putExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME, context.getApplicationInfo().packageName);

        if (context.getPackageManager().queryIntentActivities(intent, 0) != null) {// checked on start Activity

            Activity act = (Activity) context;
            act.startActivityForResult(intent, 100);
            ((Activity) context).finish();
        }
    } else
        Toast.makeText(context, "Update file does not exist!", Toast.LENGTH_SHORT).show();
}
 
Example 3
Source File: GetChromium.java    From getChromium with GNU General Public License v3.0 6 votes vote down vote up
private void instChromium() {

        // Install package ChromePublic.apk(Chromium for Android).
        Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
        intent.setDataAndType(Uri.fromFile(
                new File(String.valueOf(GetStorage.getDir
                        (this, "getChromium/chrome-android/apks/ChromePublic.apk")))),
                "application/vnd.android.package-archive");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);

        // Call to delete 'ContentShell.apk'
        deleteAPk();
    }
 
Example 4
Source File: UpdaterActivity.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onPostExecute(String result) {
    WakeLockHelper.release(mWakeLock);
    mProgressDialog.dismiss();
    if (result != null) {
        ToastCompat.makeText(getApplicationContext(), getString(R.string.failed), Toast.LENGTH_LONG).show();
        Log.d(Config.LOGTAG, "AppUpdater: failed with " + result);
        UpdaterActivity.this.finish();
    } else {
        Log.d(Config.LOGTAG, "AppUpdater: download ready in " + ((System.currentTimeMillis() - startTime) / 1000) + " sec");

        //start the installation of the latest localVersion
        Intent installIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
        installIntent.setDataAndType(FileBackend.getUriForFile(UpdaterActivity.this, file), "application/vnd.android.package-archive");
        installIntent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
        installIntent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
        installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        installIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        startActivity(installIntent);
        overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
        UpdaterActivity.this.finish();
    }
}
 
Example 5
Source File: InstallApkUtil.java    From EdXposedManager with GNU General Public License v3.0 5 votes vote down vote up
static void installApkNormally(Context context, String localFilename) {
    Intent installIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
    installIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    Uri uri;
    uri = FileProvider.getUriForFile(context, "org.meowcat.edxposed.manager.fileprovider", new File(localFilename));
    installIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    installIntent.setDataAndType(uri, DownloadsUtil.MIME_TYPE_APK);
    installIntent.putExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME, context.getApplicationInfo().packageName);
    context.startActivity(installIntent);
}
 
Example 6
Source File: UtilsLibrary.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 5 votes vote down vote up
private static void OpenNewVersion(Context context, File file) {

        Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        Uri uriFile;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            uriFile = FileProvider.getUriForFile(context, "com.moro.mtweaks.provider", file);
        } else {
            uriFile = Uri.fromFile(file);
        }
        intent.setDataAndType(uriFile,"application/vnd.android.package-archive");
        context.startActivity(Intent.createChooser(intent, "Open_Apk"));

    }
 
Example 7
Source File: AppInstaller.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
private void installWithActionInstallPackageIntent(File file, String packageName) {
  Intent promptInstall = new Intent(Intent.ACTION_INSTALL_PACKAGE);
  promptInstall.putExtra(Intent.EXTRA_RETURN_RESULT, true);
  promptInstall.putExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME, context.getApplicationContext()
      .getPackageName());
  promptInstall.setData(Uri.fromFile(file));
  promptInstall.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  promptInstall.setFlags(
      Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
  installResultCallback.onInstallationResult(
      new InstallStatus(InstallStatus.Status.INSTALLING, "Installing...", packageName));
  context.startActivity(promptInstall);
}
 
Example 8
Source File: BaseRequest.java    From AndPermission with Apache License 2.0 5 votes vote down vote up
/**
 * Start the installation.
 */
final void install() {
    if (mFile != null) {
        Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        Uri uri = AndPermission.getFileUri(mSource.getContext(), mFile);
        intent.setDataAndType(uri, "application/vnd.android.package-archive");
        mSource.startActivity(intent);
    }
}
 
Example 9
Source File: AndroidAppInstallerImpl.java    From applivery-android-sdk with Apache License 2.0 5 votes vote down vote up
private void install(String path) {
  Uri uri = composeUri(path, fileProviderAuthority);

  //Intent promptInstall = new Intent(Intent.ACTION_VIEW);
  Intent promptInstall = new Intent(Intent.ACTION_INSTALL_PACKAGE);
  promptInstall.setDataAndType(uri, APP_TYPE_ID);
  promptInstall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  promptInstall.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  context.grantUriPermission(context.getPackageName(), uri,
      Intent.FLAG_GRANT_READ_URI_PERMISSION);

  context.startActivity(promptInstall);
}
 
Example 10
Source File: InstallApk.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void onClick(View v) {
    Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
    intent.setData(Uri.fromFile(prepareApk("HelloActivity.apk")));
    intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
    intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
    intent.putExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME,
            getApplicationInfo().packageName);
    startActivityForResult(intent, REQUEST_INSTALL);
}
 
Example 11
Source File: InstallApk.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void onClick(View v) {
    Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
    intent.setData(Uri.fromFile(prepareApk("HelloActivity.apk")));
    intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
    intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
    intent.putExtra(Intent.EXTRA_ALLOW_REPLACE, true);
    intent.putExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME,
            getApplicationInfo().packageName);
    startActivityForResult(intent, REQUEST_INSTALL);
}
 
Example 12
Source File: DummyActivity.java    From Shelter with Do What The F*ck You Want To Public License 4 votes vote down vote up
private void actionInstallPackage() {
    Uri uri = null;
    if (getIntent().hasExtra("package")) {
        uri = Uri.fromParts("package", getIntent().getStringExtra("package"), null);
    }
    StrictMode.VmPolicy policy = StrictMode.getVmPolicy();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O || getIntent().hasExtra("direct_install_apk")) {
        if (getIntent().hasExtra("apk")) {
            // I really have no idea about why the "package:" uri do not work
            // after Android O, anyway we fall back to using the apk path...
            // Since I have plan to support pre-O in later versions, I keep this
            // branch in case that we reduce minSDK in the future.
            uri = Uri.fromFile(new File(getIntent().getStringExtra("apk")));
        } else if (getIntent().hasExtra("direct_install_apk")) {
            // Directly install an APK inside the profile
            // The APK will be an Uri from our own FileProviderProxy
            // which points to an opened Fd in another profile.
            // We must close the Fd when we finish.
            uri = getIntent().getParcelableExtra("direct_install_apk");
        }

        // A permissive VmPolicy must be set to work around
        // the limitation on cross-application Uri
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().build());
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        try {
            actionInstallPackageQ(uri);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } else {
        Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE, uri);
        intent.putExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME, getPackageName());
        intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
        intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        startActivityForResult(intent, REQUEST_INSTALL_PACKAGE);
    }

    // Restore the VmPolicy anyway
    StrictMode.setVmPolicy(policy);
}
 
Example 13
Source File: AppHelper.java    From KAM with GNU General Public License v3.0 4 votes vote down vote up
public static void installApk(Context context, File filename) {
    Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setData(Uri.fromFile(filename));
    context.startActivity(intent);
}
 
Example 14
Source File: InstallApk.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public void onClick(View v) {
    Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
    intent.setData(Uri.fromFile(prepareApk("HelloActivity.apk")));
    startActivity(intent);
}