AI2 Component  (Version nb184)
NougatUtil.java
Go to the documentation of this file.
1 // -*- mode: java; c-basic-offset: 2; -*-
2 // Copyright 2019-2020 MIT, All rights reserved
3 // Released under the Apache License, Version 2.0
4 // http://www.apache.org/licenses/LICENSE-2.0
5 
6 package com.google.appinventor.components.runtime.util;
7 
8 import android.net.Uri;
9 import android.os.Build;
10 import android.util.Log;
11 import androidx.core.content.FileProvider;
13 
14 import java.io.File;
15 
16 public final class NougatUtil {
17 
18  private static final String LOG_TAG = NougatUtil.class.getSimpleName();
19 
20  private NougatUtil() {
21  }
22 
23  public static Uri getPackageUri(Form form, File apk) {
24  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
25  // Use file: URI on versions of Android older the Nougat
26  return Uri.fromFile(apk);
27  } else {
28  // File provider used for SDK 24+ to get a content: URI
29  String packageName = form.$context().getPackageName();
30  Log.d(LOG_TAG, "packageName = " + packageName);
31  return FileProvider.getUriForFile(form.$context(), packageName + ".provider", apk);
32  }
33  }
34 }
com.google.appinventor.components
com.google.appinventor.components.runtime.util.NougatUtil.getPackageUri
static Uri getPackageUri(Form form, File apk)
Definition: NougatUtil.java:23
com.google.appinventor.components.runtime.Form.$context
Activity $context()
Definition: Form.java:2105
com.google.appinventor.components.runtime
Copyright 2009-2011 Google, All Rights reserved.
Definition: AccelerometerSensor.java:8
com.google.appinventor.components.runtime.util.NougatUtil
Definition: NougatUtil.java:16
com.google
com
com.google.appinventor.components.runtime.Form
Definition: Form.java:126
com.google.appinventor