You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2014/10/06 23:01:28 UTC

git commit: CB-7487 [Android] Broadcast file write This allows MTP USB shares to show the file immediately without reboot/manual refresh using 3rd party app.

Repository: cordova-plugin-file
Updated Branches:
  refs/heads/master 002788275 -> 4a820172f


CB-7487 [Android] Broadcast file write
This allows MTP USB shares to show the file immediately without reboot/manual refresh using 3rd party app.


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/4a820172
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/4a820172
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/4a820172

Branch: refs/heads/master
Commit: 4a820172fdb0ca1571faa552016c35dba96e0d7c
Parents: 0027882
Author: David Peacock <da...@gmail.com>
Authored: Fri Sep 5 18:10:39 2014 -0400
Committer: Ian Clelland <ic...@chromium.org>
Committed: Mon Oct 6 17:00:34 2014 -0400

----------------------------------------------------------------------
 src/android/LocalFilesystem.java | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/4a820172/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index e70ee22..05cda35 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -38,6 +38,9 @@ import org.json.JSONObject;
 
 import android.util.Base64;
 import android.net.Uri;
+import android.content.Context;
+import android.content.Intent;
+import android.app.Activity;
 
 public class LocalFilesystem extends Filesystem {
 
@@ -579,6 +582,7 @@ public class LocalFilesystem extends Filesystem {
             	// Always close the output
             	out.close();
             }
+            broadcastNewFile(inputURL);
         }
         catch (NullPointerException e)
         {
@@ -590,6 +594,31 @@ public class LocalFilesystem extends Filesystem {
         return rawData.length;
 	}
 
+     /**
+     * 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()) {
+            //Get the activity
+            Activity activity = this.cordova.getActivity();
+
+            //Get the context
+            Context context = activity.getApplicationContext();
+
+            //Create the URI
+            Uri uri = Uri.fromFile(file);
+
+            //Create the intent
+            Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri);
+
+            //Send broadcast of new file
+            context.sendBroadcast(intent);
+        }
+    }
+
 	@Override
 	public long truncateFileAtURL(LocalFilesystemURL inputURL, long size) throws IOException {
         File file = new File(filesystemPathForURL(inputURL));


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org