You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2015/03/13 01:12:19 UTC
cordova-plugin-file git commit: CB-8663 android: Don't notify
MediaScanner of private files
Repository: cordova-plugin-file
Updated Branches:
refs/heads/master 6cb1a2091 -> eaaaa4803
CB-8663 android: Don't notify MediaScanner of private files
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/eaaaa480
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/eaaaa480
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/eaaaa480
Branch: refs/heads/master
Commit: eaaaa4803ac458e06c55a334e114b3394feb7e97
Parents: 6cb1a20
Author: Andrew Grieve <ag...@chromium.org>
Authored: Thu Mar 12 20:11:45 2015 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Thu Mar 12 20:11:45 2015 -0400
----------------------------------------------------------------------
src/android/LocalFilesystem.java | 35 ++++++++++++++++++++++++-----------
1 file changed, 24 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eaaaa480/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index cc0ff57..35a8668 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -29,6 +29,8 @@ import org.apache.cordova.CordovaResourceApi;
import org.json.JSONException;
import org.json.JSONObject;
+import android.os.Build;
+import android.os.Environment;
import android.util.Base64;
import android.net.Uri;
import android.content.Context;
@@ -391,7 +393,8 @@ public class LocalFilesystem extends Filesystem {
try
{
byte buff[] = new byte[rawData.length];
- FileOutputStream out = new FileOutputStream(this.filesystemPathForURL(inputURL), append);
+ String absolutePath = filesystemPathForURL(inputURL);
+ FileOutputStream out = new FileOutputStream(absolutePath, append);
try {
in.read(buff, 0, buff.length);
out.write(buff, 0, rawData.length);
@@ -400,7 +403,9 @@ public class LocalFilesystem extends Filesystem {
// Always close the output
out.close();
}
- broadcastNewFile(inputURL);
+ if (isPublicDirectory(absolutePath)) {
+ broadcastNewFile(Uri.fromFile(new File(absolutePath)));
+ }
}
catch (NullPointerException e)
{
@@ -412,18 +417,26 @@ public class LocalFilesystem extends Filesystem {
return rawData.length;
}
+ private boolean isPublicDirectory(String absolutePath) {
+ // TODO: should expose a way to scan app's private files (maybe via a flag).
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ for (File f : context.getExternalMediaDirs()) {
+ if (absolutePath.startsWith(f.getAbsolutePath())) {
+ return true;
+ }
+ }
+ }
+
+ String extPath = Environment.getExternalStorageDirectory().getAbsolutePath();
+ return absolutePath.startsWith(extPath);
+ }
+
/**
* Send broadcast of new file so files appear over MTP
- *
- * @param inputURL
*/
- private void broadcastNewFile(LocalFilesystemURL inputURL) {
- File file = new File(this.filesystemPathForURL(inputURL));
- if (file.exists()) {
- Uri uri = Uri.fromFile(file);
- Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri);
- context.sendBroadcast(intent);
- }
+ private void broadcastNewFile(Uri nativeUri) {
+ Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, nativeUri);
+ context.sendBroadcast(intent);
}
@Override
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org