You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2017/11/22 00:23:32 UTC

[GitHub] maverickmishra closed pull request #165: CB-12107: (android) Trigger media scanner after downloading a file in?

maverickmishra closed pull request #165: CB-12107: (android) Trigger media scanner after downloading a file in?
URL: https://github.com/apache/cordova-plugin-file-transfer/pull/165
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/android/FileTransfer.java b/src/android/FileTransfer.java
index f9c2037..9b80891 100644
--- a/src/android/FileTransfer.java
+++ b/src/android/FileTransfer.java
@@ -62,8 +62,10 @@ Licensed to the Apache Software Foundation (ASF) under one
 import org.json.JSONException;
 import org.json.JSONObject;
 
+import android.content.Intent;
 import android.net.Uri;
 import android.os.Build;
+import android.os.Environment;
 import android.webkit.CookieManager;
 
 public class FileTransfer extends CordovaPlugin {
@@ -914,6 +916,11 @@ public void run() {
 
                         LOG.d(LOG_TAG, "Saved file: " + target);
 
+                        String path = targetUri.getPath();
+                        if( isPublicDirectory( path ) ) {
+                            Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, targetUri);
+                            cordova.getActivity().sendBroadcast(intent);
+                        }
 
                         // create FileEntry object
                         Class webViewClass = webView.getClass();
@@ -1025,4 +1032,24 @@ public void run() {
             });
         }
     }
+
+    /**
+     * Checks if path belongs to a public directory described by cordova-plugin-file
+     * https://github.com/apache/cordova-plugin-file#android-file-system-layout
+     * @param absolutePath
+     * @return boolean
+     */
+    private boolean isPublicDirectory(String absolutePath) {
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+            // Lollipop has a bug where SD cards are null.
+            for (File f : webView.getContext().getExternalMediaDirs()) {
+                if(f != null && absolutePath.startsWith(f.getAbsolutePath())) {
+                    return true;
+                }
+            }
+        }
+
+        String extPath = Environment.getExternalStorageDirectory().getAbsolutePath();
+        return absolutePath.startsWith(extPath);
+    }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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