diff options
-rw-r--r-- | res/values/strings.xml | 3 | ||||
-rw-r--r-- | src/com/android/browser/BrowserActivity.java | 33 |
2 files changed, 33 insertions, 3 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml index da61a1b..467c7c5 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -17,7 +17,8 @@ <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <!-- The name of the application. --> <string name="application_name">Browser</string> - + <!-- Displayed with a file picker to choose a file to upload --> + <string name="choose_upload">Choose file for upload</string> <!-- Name of menu item of a new tab. Also used in the title bar when displaying a new tab --> <string name="new_tab">New window</string> <!-- Name of menu item which brings up a list of the currently active tabs --> diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java index 45b2cdd..0eeb60f 100644 --- a/src/com/android/browser/BrowserActivity.java +++ b/src/com/android/browser/BrowserActivity.java @@ -130,8 +130,6 @@ import android.widget.Toast; import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; @@ -1143,6 +1141,11 @@ public class BrowserActivity extends Activity } super.onDestroy(); + if (mUploadMessage != null) { + mUploadMessage.onReceiveValue(null); + mUploadMessage = null; + } + if (mTabControl == null) return; // Remove the current tab and sub window @@ -3490,6 +3493,18 @@ public class BrowserActivity extends Activity return mVideoProgressView; } + @Override + public void openFileChooser(ValueCallback<Uri> uploadMsg) { + if (mUploadMessage != null) return; + mUploadMessage = uploadMsg; + Intent i = new Intent(Intent.ACTION_GET_CONTENT); + i.addCategory(Intent.CATEGORY_OPENABLE); + i.setType("*/*"); + BrowserActivity.this.startActivityForResult( + Intent.createChooser(i, getString(R.string.choose_upload)), + FILE_SELECTED); + } + /** * Deliver a list of already-visited URLs * @hide pending API Council approval @@ -3510,6 +3525,11 @@ public class BrowserActivity extends Activity }; }; + /* + * The Object used to inform the WebView of the file to upload. + */ + private ValueCallback<Uri> mUploadMessage; + /** * Notify the host application a download should be done, or that * the data should be streamed if a streaming viewer is available. @@ -4227,6 +4247,14 @@ public class BrowserActivity extends Activity } } break; + // Choose a file from the file picker. + case FILE_SELECTED: + if (null == mUploadMessage) break; + Uri result = intent == null || resultCode != RESULT_OK ? null + : intent.getData(); + mUploadMessage.onReceiveValue(result); + mUploadMessage = null; + break; default: break; } @@ -4576,6 +4604,7 @@ public class BrowserActivity extends Activity final static int COMBO_PAGE = 1; final static int DOWNLOAD_PAGE = 2; final static int PREFERENCES_PAGE = 3; + final static int FILE_SELECTED = 4; // the default <video> poster private Bitmap mDefaultVideoPoster; |