Commit 6d606ea1 authored by Colin Yang's avatar Colin Yang Committed by Jeffrey Schiller

Unified file provider source (#1563)

* Unified file provider source
parent 653ecab0
......@@ -16,8 +16,6 @@ import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import android.util.Log;
......@@ -38,6 +36,7 @@ import com.google.appinventor.components.runtime.errors.YailRuntimeError;
import com.google.appinventor.components.runtime.util.AnimationUtil;
import com.google.appinventor.components.runtime.util.ErrorMessages;
import com.google.appinventor.components.runtime.util.NougatUtil;
import com.google.appinventor.components.runtime.util.YailList;
import java.io.File;
......@@ -475,9 +474,7 @@ public class ActivityStarter extends AndroidNonvisibleComponent
File file = new File(uri.getPath());
if (file.isFile()) {
Log.d(LOG_TAG, "It's a file");
String packageName = form.$context().getPackageName();
uri = FileProvider.getUriForFile(form.$context(), packageName + ".provider", file);
uri = NougatUtil.getPackageUri(form, file);
intent = new Intent(action);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Log.d(LOG_TAG, "added permissions"); // adb log shows this gets printed
......
......@@ -6,7 +6,6 @@
package com.google.appinventor.components.runtime;
import com.google.appinventor.components.annotations.DesignerProperty;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.PropertyCategory;
import com.google.appinventor.components.annotations.SimpleEvent;
......@@ -15,9 +14,9 @@ import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.annotations.UsesPermissions;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.common.PropertyTypeConstants;
import com.google.appinventor.components.common.YaVersion;
import com.google.appinventor.components.runtime.util.ErrorMessages;
import com.google.appinventor.components.runtime.util.NougatUtil;
import android.app.Activity;
import android.content.ContentValues;
......@@ -213,7 +212,7 @@ public class Camera extends AndroidNonvisibleComponent
*/
private void scanFileToAdd(File image) {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri contentUri = Uri.fromFile(image);
Uri contentUri = NougatUtil.getPackageUri(form, image);
mediaScanIntent.setData(contentUri);
container.$context().getApplicationContext().sendBroadcast(mediaScanIntent);
}
......
......@@ -10,8 +10,6 @@ import android.content.Intent;
import android.net.Uri;
import android.support.v4.content.FileProvider;
import android.webkit.MimeTypeMap;
import com.google.appinventor.components.annotations.DesignerComponent;
......@@ -23,6 +21,7 @@ import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.common.YaVersion;
import com.google.appinventor.components.runtime.util.ErrorMessages;
import com.google.appinventor.components.runtime.util.NougatUtil;
import java.io.File;
......@@ -90,9 +89,6 @@ public class Sharing extends AndroidNonvisibleComponent {
+ "installed on the phone by displaying a list of available apps and allowing the user to " +
" choose one from the list. The selected app will open with the file and message inserted on it.")
public void ShareFileWithMessage(String file, String message) {
String packageName = form.$context().getPackageName();
if (!file.startsWith("file://"))
file = "file://" + file;
......@@ -103,8 +99,7 @@ public class Sharing extends AndroidNonvisibleComponent {
MimeTypeMap mime = MimeTypeMap.getSingleton();
String type = mime.getMimeTypeFromExtension(fileExtension);
Uri shareableUri = FileProvider.getUriForFile(form.$context(),
packageName + ".provider", imageFile);
Uri shareableUri = NougatUtil.getPackageUri(form, imageFile);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, shareableUri);
shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
......
......@@ -10,8 +10,6 @@ import android.net.Uri;
import android.os.Environment;
import android.support.v4.content.FileProvider;
import android.util.Log;
import com.google.appinventor.components.runtime.Form;
......@@ -96,8 +94,7 @@ public class AssetFetcher {
try {
Form form = Form.getActiveForm();
Intent intent = new Intent(Intent.ACTION_VIEW);
String packageName = form.$context().getPackageName();
Uri packageuri = FileProvider.getUriForFile(form.$context(), packageName + ".provider", assetFile);
Uri packageuri = NougatUtil.getPackageUri(form, assetFile);
intent.setDataAndType(packageuri, "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
form.startActivity(intent);
......
......@@ -11,11 +11,8 @@ import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.support.v4.content.FileProvider;
import android.util.Log;
import com.google.appinventor.components.runtime.Form;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment