How to modify file selector options in a webview?
up vote
0
down vote
favorite
In my application, I'm using a webview page in which users can select files to upload. It's only showing two options for Camera
and Documents
. But in google chrome or even other webview applications, there are more options, such as voice recorder
.
I'm using WebChromeClient
as base for my pages. I used the startActivityOpenChooser
before file opener prompt, which I believe this function is all I need to change, if possible.
// openFileChooser for Android < 3.0
public void openFileChooser(ValueCallback<Uri> uploadMsg)
openFileChooser(uploadMsg, "");
...
public void startActivityOpenChooser(String acceptType)
File imageStorageDir = new File(mainActivity.getExternalCacheDir(), "user_upload_files");
if (!imageStorageDir.exists())
// Create user_upload_files at sdcard
imageStorageDir.mkdirs();
// Create camera captured image file path and name
File file = new File(imageStorageDir + File.separator + "IMG_" + String.valueOf(System.currentTimeMillis()) + ".jpg");
mainActivity.mCapturedImageURI = Uri.fromFile(file);
// Camera capture image intent
final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mainActivity.mCapturedImageURI);
Intent i = null;
if (Build.VERSION.SDK_INT < 19)
i = new Intent();
i.setAction(Intent.ACTION_GET_CONTENT);
else
i = new Intent(Intent.ACTION_OPEN_DOCUMENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
// Create file chooser intent
Intent chooserIntent = Intent.createChooser(i, mainActivity.getResources().getString(R.string.choose_file_for_upload));
// Set camera intent to file chooser
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new ParcelablecaptureIntent);
// On select image call onActivityResult method of activity
mainActivity.startActivityForResult(chooserIntent, MainActivity.FILECHOOSER_RESULTCODE);
Here is an image showing the difference:
java android android-webview google-chrome-webview
add a comment |
up vote
0
down vote
favorite
In my application, I'm using a webview page in which users can select files to upload. It's only showing two options for Camera
and Documents
. But in google chrome or even other webview applications, there are more options, such as voice recorder
.
I'm using WebChromeClient
as base for my pages. I used the startActivityOpenChooser
before file opener prompt, which I believe this function is all I need to change, if possible.
// openFileChooser for Android < 3.0
public void openFileChooser(ValueCallback<Uri> uploadMsg)
openFileChooser(uploadMsg, "");
...
public void startActivityOpenChooser(String acceptType)
File imageStorageDir = new File(mainActivity.getExternalCacheDir(), "user_upload_files");
if (!imageStorageDir.exists())
// Create user_upload_files at sdcard
imageStorageDir.mkdirs();
// Create camera captured image file path and name
File file = new File(imageStorageDir + File.separator + "IMG_" + String.valueOf(System.currentTimeMillis()) + ".jpg");
mainActivity.mCapturedImageURI = Uri.fromFile(file);
// Camera capture image intent
final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mainActivity.mCapturedImageURI);
Intent i = null;
if (Build.VERSION.SDK_INT < 19)
i = new Intent();
i.setAction(Intent.ACTION_GET_CONTENT);
else
i = new Intent(Intent.ACTION_OPEN_DOCUMENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
// Create file chooser intent
Intent chooserIntent = Intent.createChooser(i, mainActivity.getResources().getString(R.string.choose_file_for_upload));
// Set camera intent to file chooser
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new ParcelablecaptureIntent);
// On select image call onActivityResult method of activity
mainActivity.startActivityForResult(chooserIntent, MainActivity.FILECHOOSER_RESULTCODE);
Here is an image showing the difference:
java android android-webview google-chrome-webview
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
In my application, I'm using a webview page in which users can select files to upload. It's only showing two options for Camera
and Documents
. But in google chrome or even other webview applications, there are more options, such as voice recorder
.
I'm using WebChromeClient
as base for my pages. I used the startActivityOpenChooser
before file opener prompt, which I believe this function is all I need to change, if possible.
// openFileChooser for Android < 3.0
public void openFileChooser(ValueCallback<Uri> uploadMsg)
openFileChooser(uploadMsg, "");
...
public void startActivityOpenChooser(String acceptType)
File imageStorageDir = new File(mainActivity.getExternalCacheDir(), "user_upload_files");
if (!imageStorageDir.exists())
// Create user_upload_files at sdcard
imageStorageDir.mkdirs();
// Create camera captured image file path and name
File file = new File(imageStorageDir + File.separator + "IMG_" + String.valueOf(System.currentTimeMillis()) + ".jpg");
mainActivity.mCapturedImageURI = Uri.fromFile(file);
// Camera capture image intent
final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mainActivity.mCapturedImageURI);
Intent i = null;
if (Build.VERSION.SDK_INT < 19)
i = new Intent();
i.setAction(Intent.ACTION_GET_CONTENT);
else
i = new Intent(Intent.ACTION_OPEN_DOCUMENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
// Create file chooser intent
Intent chooserIntent = Intent.createChooser(i, mainActivity.getResources().getString(R.string.choose_file_for_upload));
// Set camera intent to file chooser
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new ParcelablecaptureIntent);
// On select image call onActivityResult method of activity
mainActivity.startActivityForResult(chooserIntent, MainActivity.FILECHOOSER_RESULTCODE);
Here is an image showing the difference:
java android android-webview google-chrome-webview
In my application, I'm using a webview page in which users can select files to upload. It's only showing two options for Camera
and Documents
. But in google chrome or even other webview applications, there are more options, such as voice recorder
.
I'm using WebChromeClient
as base for my pages. I used the startActivityOpenChooser
before file opener prompt, which I believe this function is all I need to change, if possible.
// openFileChooser for Android < 3.0
public void openFileChooser(ValueCallback<Uri> uploadMsg)
openFileChooser(uploadMsg, "");
...
public void startActivityOpenChooser(String acceptType)
File imageStorageDir = new File(mainActivity.getExternalCacheDir(), "user_upload_files");
if (!imageStorageDir.exists())
// Create user_upload_files at sdcard
imageStorageDir.mkdirs();
// Create camera captured image file path and name
File file = new File(imageStorageDir + File.separator + "IMG_" + String.valueOf(System.currentTimeMillis()) + ".jpg");
mainActivity.mCapturedImageURI = Uri.fromFile(file);
// Camera capture image intent
final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mainActivity.mCapturedImageURI);
Intent i = null;
if (Build.VERSION.SDK_INT < 19)
i = new Intent();
i.setAction(Intent.ACTION_GET_CONTENT);
else
i = new Intent(Intent.ACTION_OPEN_DOCUMENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
// Create file chooser intent
Intent chooserIntent = Intent.createChooser(i, mainActivity.getResources().getString(R.string.choose_file_for_upload));
// Set camera intent to file chooser
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new ParcelablecaptureIntent);
// On select image call onActivityResult method of activity
mainActivity.startActivityForResult(chooserIntent, MainActivity.FILECHOOSER_RESULTCODE);
Here is an image showing the difference:
java android android-webview google-chrome-webview
java android android-webview google-chrome-webview
edited Nov 10 at 11:53
Kling Klang
32k156286
32k156286
asked Nov 10 at 10:25
ananda
4741929
4741929
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238008%2fhow-to-modify-file-selector-options-in-a-webview%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password