AI2 Component  (Version nb184)
QUtil.java
Go to the documentation of this file.
1 // -*- mode: java; c-basic-offset: 2; -*-
2 // Copyright © 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.content.Context;
9 import android.os.Build;
10 import android.os.Environment;
11 import java.io.File;
12 
18 public class QUtil {
19 
36  public static String getExternalStoragePath(Context context, boolean forcePrivate) {
37  return getExternalStorageDir(context, forcePrivate).getAbsolutePath();
38  }
39 
53  public static String getExternalStoragePath(Context context) {
54  return getExternalStoragePath(context, false);
55  }
56 
72  public static File getExternalStorageDir(Context context) {
73  return getExternalStorageDir(context, false);
74  }
75 
92  @SuppressWarnings("deprecation")
93  public static File getExternalStorageDir(Context context, boolean forcePrivate) {
94  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO) {
95  // Context#getExternalFilesDir didn't exist until Froyo
96  return Environment.getExternalStorageDirectory();
97  }
98  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q || forcePrivate) {
99  // Q no longer allows using getExternalStorageDirectory()
100  return context.getExternalFilesDir(null);
101  } else {
102  return Environment.getExternalStorageDirectory();
103  }
104  }
105 
122  public static String getReplAssetPath(Context context, boolean forcePrivate) {
123  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
124  return getExternalStoragePath(context, forcePrivate) + "/assets/";
125  } else {
126  return getExternalStoragePath(context, forcePrivate) + "/AppInventor/assets/";
127  }
128  }
129 
143  public static String getReplAssetPath(Context context) {
144  return getReplAssetPath(context, false);
145  }
146 
158  public static String getReplDataPath(Context context, boolean forcePrivate) {
159  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
160  return getExternalStoragePath(context, forcePrivate) + "/data/";
161  } else {
162  return getExternalStoragePath(context, forcePrivate) + "/AppInventor/data/";
163  }
164  }
165 
174  public static String getReplDataPath(Context context) {
175  return getReplDataPath(context, false);
176  }
177 }
com.google.appinventor.components.runtime.util.QUtil.getExternalStoragePath
static String getExternalStoragePath(Context context, boolean forcePrivate)
Definition: QUtil.java:36
com.google.appinventor.components.runtime.util.QUtil.getReplDataPath
static String getReplDataPath(Context context)
Definition: QUtil.java:174
com.google.appinventor.components.runtime.util.QUtil.getReplAssetPath
static String getReplAssetPath(Context context, boolean forcePrivate)
Definition: QUtil.java:122
com.google.appinventor.components.runtime.util.QUtil
Definition: QUtil.java:18
com.google.appinventor.components.runtime.util.QUtil.getReplDataPath
static String getReplDataPath(Context context, boolean forcePrivate)
Definition: QUtil.java:158
com.google.appinventor.components.runtime.util.QUtil.getExternalStorageDir
static File getExternalStorageDir(Context context)
Definition: QUtil.java:72
com.google.appinventor.components.runtime.util.QUtil.getExternalStoragePath
static String getExternalStoragePath(Context context)
Definition: QUtil.java:53
com.google.appinventor.components.runtime.util.QUtil.getReplAssetPath
static String getReplAssetPath(Context context)
Definition: QUtil.java:143