CB-9148 (android) Add Support for input[type=file] File Chooser
This closes #205
This commit is contained in:
parent
c53be403e2
commit
fe686b3c1f
@ -29,7 +29,6 @@ import android.net.Uri;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
import android.util.Log;
|
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
@ -734,7 +733,7 @@ public class InAppBrowser extends CordovaPlugin {
|
|||||||
// For Android 5.0+
|
// For Android 5.0+
|
||||||
public boolean onShowFileChooser (WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams)
|
public boolean onShowFileChooser (WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams)
|
||||||
{
|
{
|
||||||
Log.d(LOG_TAG, "File Chooser 5.0+");
|
LOG.d(LOG_TAG, "File Chooser 5.0+");
|
||||||
// If callback exists, finish it.
|
// If callback exists, finish it.
|
||||||
if(mUploadCallbackLollipop != null) {
|
if(mUploadCallbackLollipop != null) {
|
||||||
mUploadCallbackLollipop.onReceiveValue(null);
|
mUploadCallbackLollipop.onReceiveValue(null);
|
||||||
@ -746,16 +745,15 @@ public class InAppBrowser extends CordovaPlugin {
|
|||||||
content.addCategory(Intent.CATEGORY_OPENABLE);
|
content.addCategory(Intent.CATEGORY_OPENABLE);
|
||||||
content.setType("*/*");
|
content.setType("*/*");
|
||||||
|
|
||||||
// [important] Register ActvityResultCallback on Cordova
|
// Run cordova startActivityForResult
|
||||||
cordova.setActivityResultCallback(InAppBrowser.this);
|
cordova.startActivityForResult(InAppBrowser.this, Intent.createChooser(content, "Select File"), FILECHOOSER_REQUESTCODE_LOLLIPOP);
|
||||||
cordova.getActivity().startActivityForResult(content, FILECHOOSER_REQUESTCODE_LOLLIPOP);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For Android 4.1+
|
// For Android 4.1+
|
||||||
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture)
|
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture)
|
||||||
{
|
{
|
||||||
Log.d(LOG_TAG, "File Chooser 4.1+");
|
LOG.d(LOG_TAG, "File Chooser 4.1+");
|
||||||
// Call file chooser for Android 3.0+
|
// Call file chooser for Android 3.0+
|
||||||
openFileChooser(uploadMsg, acceptType);
|
openFileChooser(uploadMsg, acceptType);
|
||||||
}
|
}
|
||||||
@ -763,20 +761,13 @@ public class InAppBrowser extends CordovaPlugin {
|
|||||||
// For Android 3.0+
|
// For Android 3.0+
|
||||||
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType)
|
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType)
|
||||||
{
|
{
|
||||||
Log.d(LOG_TAG, "File Chooser 3.0+");
|
LOG.d(LOG_TAG, "File Chooser 3.0+");
|
||||||
mUploadCallback = uploadMsg;
|
mUploadCallback = uploadMsg;
|
||||||
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
|
Intent content = new Intent(Intent.ACTION_GET_CONTENT);
|
||||||
i.addCategory(Intent.CATEGORY_OPENABLE);
|
content.addCategory(Intent.CATEGORY_OPENABLE);
|
||||||
|
|
||||||
cordova.setActivityResultCallback(InAppBrowser.this);
|
// run startActivityForResult
|
||||||
cordova.getActivity().startActivityForResult( Intent.createChooser(i, "File Chooser"), FILECHOOSER_REQUESTCODE);
|
cordova.startActivityForResult(InAppBrowser.this, Intent.createChooser(content, "Select File"), FILECHOOSER_REQUESTCODE);
|
||||||
}
|
|
||||||
|
|
||||||
// For Android < 3.0
|
|
||||||
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
|
|
||||||
Log.d(LOG_TAG, "File Chooser 3.0 <");
|
|
||||||
// Call file chooser for Android 3.0+
|
|
||||||
openFileChooser(uploadMsg, "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -898,7 +889,7 @@ public class InAppBrowser extends CordovaPlugin {
|
|||||||
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||||
// For Android >= 5.0
|
// For Android >= 5.0
|
||||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
Log.i("mytag", "onActivityResult (For Android >= 5.0)");
|
LOG.d(LOG_TAG, "onActivityResult (For Android >= 5.0)");
|
||||||
// If RequestCode or Callback is Invalid
|
// If RequestCode or Callback is Invalid
|
||||||
if(requestCode != FILECHOOSER_REQUESTCODE_LOLLIPOP || mUploadCallbackLollipop == null) {
|
if(requestCode != FILECHOOSER_REQUESTCODE_LOLLIPOP || mUploadCallbackLollipop == null) {
|
||||||
super.onActivityResult(requestCode, resultCode, intent);
|
super.onActivityResult(requestCode, resultCode, intent);
|
||||||
@ -909,7 +900,7 @@ public class InAppBrowser extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
// For Android < 5.0
|
// For Android < 5.0
|
||||||
else {
|
else {
|
||||||
Log.i("mytag", "onActivityResult (For Android < 5.0)");
|
LOG.d(LOG_TAG, "onActivityResult (For Android < 5.0)");
|
||||||
// If RequestCode or Callback is Invalid
|
// If RequestCode or Callback is Invalid
|
||||||
if(requestCode != FILECHOOSER_REQUESTCODE || mUploadCallback == null) {
|
if(requestCode != FILECHOOSER_REQUESTCODE || mUploadCallback == null) {
|
||||||
super.onActivityResult(requestCode, resultCode, intent);
|
super.onActivityResult(requestCode, resultCode, intent);
|
||||||
|
Loading…
Reference in New Issue
Block a user