Web Learners, This blog is gonna give you huge knowledge about Mobile App Development, Game development, Internet Marketing, Social Network Marketing, Search Engine Optimization (SEO) ,Mobile Marketing, and website and web application Code knowledge such as HTML, CSS, JavaScript etc. This site is also gonna give you free tools and software with installation guides. Most important Tips and tricks about marketing, software installation and Coding is always available.
Hi, Everyone! I have got many requests and comment about "File upload not working in android webview app", also "can not uploading pdf or video file in android webview app", you all have requested me to help you for solving the problem.
Today I will solve all the problems about "How to enable or support file uploading in android webview app", "How to allow any type file uploading such as pdf, ppt, audio, video, image, txt"? anything you will be able to upload in your webview android apps. Just follow my tutorial from beginning to end. In the previous video, I have showed you How to Enable Download in Android Webview App.
So, Let's start, First of all, you need to add 3 permission for "access camera, write in external storage and Internet" in your AndroidManifest.xml file.
Code:
After adding the permission, now need to move to the "MainActivity.java" file, now let's take 5 variable, which are:
Code:
Let's demonstrate, why we have taken these variable, we have taken a private static string file called "file_type", this is for storing file type we want to upload in our webview app, such as pdf, ppt, pptx, ppt, audio, video, image, doc, zip, RTF, txt, etc.
As we want to allow all types of these files uploading in our android webview app, so we have defined file_type = "*/*". "*/*" this means it will allow all types of file uploading in the android webview app.
cam_file_data: This String variable "cam_file_data" for storing camera file information.
ValueCallback<Uri> file_data: We have taken the "ValueCallback" variable, we have named it "file_data", this will store data after selecting the file.
ValueCallback<Uri[]> file_path: Another "ValueCallback" variable, we named it file_path, this will store file location.
Now let's move to the "onCreate" method, and will write a function method called onShowFileChooser in our setWebChromeClient, and all the necessary code will write on this function, See the Below Code:
Code:
Now we will write a function "onActivityResult" for selecting the file from the Camera or SD card in android webview app. This function will be outside of "onCreate" method.See the Below Code:
Code:
Now we will write function called "onConfigurationChanged"
Code:
Now we will write a function "file_permission" for checking and asking for required file permissions.
Code:
We have taken a variable "photoFile" in the "onActivityResult" function, there we have stored a function called "create_image()". Now we will create that function.
Code:
Now we will write function for video file
Code:
We have finished the coding. Now Let's run our project and check whether any type of file is uploading in our android webview app or not.
Figure: How to enable file upload in webview android
As you can see from the above image, I have successfully uploaded an audio MP3 file, MP4 video file, and image. This way you will able to do android webview upload files, upload all types of files, pdf, ppt, audio, video, image, txt etc.
In the next tutorial, I will show you How to enable multiple file upload in the Android webview app.
how to access camera from within webview. in my web application there is a function to scan using camera but it doesn't work in webview while in browser it works fine, do you have a solution?
I am nothing but a online business man. more than 12 years of experiences in online business. I have learned everything of my own. You know if you learn something from your own you will learn more than somebody taught you on that topic. Long story short, I did lots of experiments, did lots of online jobs for the people, got lots of errors changes the way again and again. At the end got the perfect knowledge about online business. I would love to let you know all of my 12 years of knowledge about online business. Keep in touch with the blog to be knowledged about online business.
Thanks
, click here →
bidvertiser
About Site
WebLearners is a blog to teach online business such as E-com Business, App Business, SEO Business, Digital Marketing, etc. Lots of free tools and web applications will be given for free. Actually, We will dig deep on every topic one by one. It will be a long journey but in the end, you will be a succesful online businessman. Tutorials are expressed as a guideline for the person who wishes to start an online business. Readers can ask any questions or can ask for help to develop their business. We will be happy to help.
, click here →
How to Enable Download in Android Webview App? In the Last post of our Webview Series, I have shown How to Add Splash Screen in Any Androi...
bidvertiser
About Me
I am nothing but a online business man. more than 12 years of experiences in online business. I have learned everything of my own. You know if you learn something from your own you will learn more than somebody taught you on that topic. Long story short, I did lots of experiments, did lots of online jobs for the people, got lots of errors changes the way again and again. At the end got the perfect knowledge about online business. I would love to let you know all of my 12 years of knowledge about online business. Keep in touch with the blog to be knowledged about online business.
Thanks
, click here →
can I get the total code example of "MainActivity.java" file, bcz without it unable to identify the places to put coad
ReplyDeleteHello, All your code is in MainActivity.java
ReplyDeletein my template, it is different.
I stuck here :
private static String file_type = "*/*";
private String cam_file_data = null;
private ValueCallback file_data;
private ValueCallback file_path;
private final static int file_req_code = 1;
can not add that code.
How can I download the android project?
ReplyDeleteDo you have a working solution for Kotlin?
how to access camera from within webview.
ReplyDeletein my web application there is a function to scan using camera but it doesn't work in webview while in browser it works fine, do you have a solution?
can i pls get link to your android webview source code, i still could not get it to work with your code
ReplyDeleteit's work thank you very much..
ReplyDeleteGood man its work
ReplyDeleteThank you madam
ReplyDelete