For the openFileChooser () file selection method, a method that does not call WebChromeClient from Kitkat 4.4

I have one hi-bride application in which there is a file collector on one html page and I want to load this page in an Android web browser.

These builders work well in the device browser, but not in web browsing.

To support this, I use one hidden WebChromeClient method, which is below

public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType){ /**updated, out of the IF **/ mUploadMessage = uploadMsg; /**updated, out of the IF **/ if(boolFileChooser){ //Take picture from filechooser Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); startActivityForResult( Intent.createChooser( i, "Pick File.." ), FILECHOOSER_RESULTCODE ); } else { //Take photo and upload picture Intent cameraIntent = new Intent("android.media.action.IMAGE_CAPTURE"); photo = new File(Environment.getExternalStorageDirectory(), "Pic.jpg"); if(photo.exists()) photo.delete(); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo)); mCapturedImageURI = Uri.fromFile(photo); startActivityForResult(cameraIntent, CAMERAREQUEST_RESULTCODE); } } // Per Android < 3.0 public void openFileChooser(ValueCallback<Uri> uploadMsg){ openFileChooser(uploadMsg, ""); } //Aftre public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { openFileChooser(uploadMsg, ""); } 

It worked fine until 4.3, but from 4.4 this method is not called. And they said https://code.google.com/p/android/issues/detail?id=62220 . This has been removed.

Does anyone know some alternative way. Please let me know, your help will be greatly appreciated.

+7
javascript android
source share
3 answers

There is no way for the openFileChooser method after 4.3, since Google deleted it, and they will come up with another way to process this file to select the file in the next version (confirmed by Google engineer).

I switched to a hybrid architecture and recorded a built-in function for selecting files.

+4
source share

In Android 5.0, they implemented onShowFileChooser () , with which you can use the input form field in a web view and run a selection file, select images and files from the device.

+1
source share
 Bitmap bitmap; private static final int READ_REQUEST_CODE = 42; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main); Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); // Filter to only show results that can be "opened", such as a // file (as opposed to a list of contacts or timezones) intent.addCategory(Intent.CATEGORY_OPENABLE); // Filter to show only images, using the image MIME data type. // If one wanted to search for ogg vorbis files, the type would be "audio/ogg". // To search for all documents available via installed storage providers, // it would be "*/*". intent.setType("image/*"); startActivityForResult(intent, READ_REQUEST_CODE); } @Override public void onActivityResult(int requestCode, int resultCode, Intent resultData) { // The ACTION_OPEN_DOCUMENT intent was sent with the request code // READ_REQUEST_CODE. If the request code seen here doesn't match, it the // response to some other intent, and the code below shouldn't run at all. if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK) { // The document selected by the user won't be returned in the intent. // Instead, a URI to that document will be contained in the return intent // provided to this method as a parameter. // Pull that URI using resultData.getData(). Uri uri = null; if (resultData != null) { uri = resultData.getData(); try { bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(),uri); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } ImageView my_img_view = (ImageView ) findViewById (R.id.uploadlayout2); my_img_view.setImageBitmap(bitmap); } } } 
-one
source share

All Articles