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.
How to Enable File Upload in Android Webview App? That's what most of the people search in the google and youtube. Because this is the most complicated part of the webview app development.
Are you stuck with the problem "How to allow file upload and download in webview" also? Don't worry, Today I am going to show you how to write the code in android studio to support file upload in android webview app.
Before we move to the tutorial about uploading part I would like to let you know that we already have a post about "How to enable download in webview?". However Let's Start.
First of all, You need to give 3 permission in AndoidManifest.xml. Those are given below:
Code:
After that, you need to write code in MainActivity.java file. You need to take some global variable for opening file chooser with camera option, see below code:
Code:
After that, you need to write code for showing "file chooser". Just copy the below code and paste it into your WebChromeClient function. By the way, you can see below code contain "web" is my variable name, I have retrieved and stored my Webview from activity_main.xml.you need to replace that variable "web" with your variable name.
Code:
Then you need to write Override function after "onCreate", See below code.
Code:
Don't forget to write this line of code in your "strings.xml" file.
Code:
Whenever you will paste these codes in your project you see lots of red words. you need to click on that red word then press "alt+Enter" then it will import class automatically. Or you can just copy below import class and paste in your import section. all the Error will go.
Code:
After paste above import class, you will see almost all the error gone, only 5 error still there, they are "uri", "uploadMsg" and "result". you need to click on "result" then will show suggestion you need to click on that, then all the error will go. See below picture:
So, the whole final code will be in MainActivty.java is:
Code:
In conclusion, we have finished our coding for our Webview App. Now we will run our project on Emulator. As you can see in my screenshot, it's working perfectly.
By the way, If you face any problem, let us know in the comment box below. We will try our best to solve your problem. Thanks.
Please follow the videos properly and slowly. I have checked again and again its working. you can try by changing emulator devices. Thank you for your comment.
Please follow the videos properly and slowly. I have checked again and again its working. you can try by changing emulator devices. Thank you for your comment.
Please follow the videos properly and slowly. I have checked again and again its working. you can try by changing emulator devices. Thank you for your comment.
Please follow the videos properly and slowly. I have checked again and again its working. you can try by changing emulator devices. Thank you for your comment.
Please follow the videos properly and slowly. I have checked again and again its working. you can try by changing emulator devices. Thank you for your comment.
Hi there, tried this code and gallery upload works perfect, but the camera upload does not. the camera app opens, i shoot a picture, click okay, and it doesnt upload. Any ideas or recommendations?
Please follow the videos properly and slowly. I have checked again and again its working. you can try by changing emulator devices. Thank you for your comment.
Are you targeting Android API 29? Since Environment.getExternalStoragePublicDirectory() were deprecated in Android API 29, I suggest you to replace File imageStorageDir = new File(Environment.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "DirectoryNameHere"); with File imageStorageDir = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES),"yourPictFolderName");
Please follow the videos properly and slowly. I have checked again and again its working. you can try by changing emulator devices. Thank you for your comment.
Its working and not working, Its working among others to show file chooser, but it's not working , the result from camera return nothing I user galaxy m20 android 10 Is it createImageFile function failed ?
Your the best, Your Tutorials and Code Providing a good platform for people like us, stay blessed. I wanna mention one thing in few comments they mentioned the camera issue the problem is that "The upload wasn't working at all after Google WebView update" Present I'm trying to find code to resolve the issue and madam if you can find the solution means it would be helpful.
I want a code only for file upload in webveiw not from camera. File may be pdf, doc etc. Please make a video for this, there is not enough and good video for this on youtube.
The video was very good, it helped me a lot. Thank you. My web application loads pdf in the same option. you have a similar video on how to upload the pdf?.
Assalamualaikum. it's working. thank you very much. but I have any little problem just little problem, when I take picture from my camera, I don't see file name on my file choosen web. so my picture can't be upload because is empty. can you help it?
but if I choose file on my file, it's working and I can upload very well. Thanks
hi thanks first of all for making this great tutorial series i have the same issue gallery work fine but camera uploads not working i copy and paste code as per video directions and do it 4th times also allow permissions to camera but issue is there please guide the solution thanks
Hi, a code like this worked since android 10. When the app runs on android 10 onShowFileChooser is not called at all. Do you have any idea or a workaround ?
Hi, this works before android 10. If the app is running on android 10 the method "onShowFileChooser" is not called at all. Do you know any workaround ?
How can use code for upload with download support. Here you guided for upload file only and for download in previous tutorial. When I used code for download and after that used the above codes for upload, there are errors of some code already used.
Hi, it worked but I can't select more that one file. I can only pick one image file at a time yet I really want to be able to select multiple files at a time. Any help will really be helpful
If this method is not working for you, then you can follow my another method. Here is the link: https://weblearners.blogspot.com/2021/06/how-to-enable-video-image-and-file-upload-in-android-webview-app.html
Thanks a lot for this post, Can I know how to remove camera option from this? Bcz I only need document choosing method. Any way this post was very very helpful to me so Thank you again 🤝🤍🤍🤍
In my case uploading is working fine but in case i call this function along with onCreateWindow, onCreateWindow method is working fine but file uploading option does not working, kindly help 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 →
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 →
i am not able to upload images directly from camera.Documents folder is working properly.
ReplyDeletePlease follow the videos properly and slowly. I have checked again and again its working. you can try by changing emulator devices. Thank you for your comment.
Deletesame here, not working upload directly from the camera. I tried on my physical device, not work either.
Deletehttps://youtu.be/Nt0g2o8aklA
DeleteThis not work Android version 10 and 11
DeleteThanks so much. You're a live saver
ReplyDeleteYou are most welcome :)
DeleteThanks so much. You're a life saver. Had issues with placement of some codes but I figured it out. This works, thanks again.
ReplyDeleteYou are most welcome :)
DeleteCamera is not getting initiated
ReplyDeletePlease follow the videos properly and slowly. I have checked again and again its working. you can try by changing emulator devices. Thank you for your comment.
Deleteif camera does not work check if you have this:
Deleteif you have it YOU NEED TO REMOVE IT.. then it will work (its stupid I know)
https://youtu.be/Nt0g2o8aklA
Deletecamera is not getting initiated . I am using Lenovo k50 android 6.0
ReplyDeletePlease follow the videos properly and slowly. I have checked again and again its working. you can try by changing emulator devices. Thank you for your comment.
Deletecamera is not getting initiated. I am using Lenovo k50 android 6.0
ReplyDeletePlease follow the videos properly and slowly. I have checked again and again its working. you can try by changing emulator devices. Thank you for your comment.
Deletehttps://youtu.be/Nt0g2o8aklA
DeleteHow to Enable File Upload and location capture(longitude and latitude) in Android Webview App | Webview App Development Series Part 11
ReplyDeleteOk I will try to create video tutorial on it.
Deletehttps://www.youtube.com/watch?v=Nt0g2o8aklA&list=PLCK6ZjZwBKWGvyXnEUoC8MZ4xRKEUHKL1&index=21&ab_channel=TricksSoftware
Deletewhy can't open camera..? even though add uses permission camera
ReplyDeletePlease follow the videos properly and slowly. I have checked again and again its working. you can try by changing emulator devices. Thank you for your comment.
Deletehttps://youtu.be/Nt0g2o8aklA
DeleteYou are the best . It works exactly with the changes you previously mentioned.
ReplyDeleteTHANK YOU!!
You are most welcome :)
DeleteYou are the best . It works exactly with the changes you previously mentioned.
ReplyDeleteTHANK YOU!!!!!
You are most welcome :)
DeleteHi there, tried this code and gallery upload works perfect, but the camera upload does not. the camera app opens, i shoot a picture, click okay, and it doesnt upload. Any ideas or recommendations?
ReplyDeletePlease follow the videos properly and slowly. I have checked again and again its working. you can try by changing emulator devices. Thank you for your comment.
DeleteYou may not be requesting for Camera permission. So go to the app setting and click permission and enable camera. It should work.
DeleteEnable Permission for Camera in app settings.
DeleteAre you targeting Android API 29?
DeleteSince Environment.getExternalStoragePublicDirectory() were deprecated in Android API 29, I suggest you to replace
File imageStorageDir = new File(Environment.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "DirectoryNameHere");
with
File imageStorageDir = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES),"yourPictFolderName");
https://youtu.be/Nt0g2o8aklA
DeleteThanks so much but my own not working still
ReplyDeletePlease follow the videos properly and slowly. I have checked again and again its working. you can try by changing emulator devices. Thank you for your comment.
DeleteThank you. Nice tutorial, it solved my issue.
ReplyDeleteYou are most welcome :)
DeleteI have tried everything but still the red mark appears, what could be a problem?
DeleteI tried all of the codes above but still I see the red mark om createImageFile(), and uploadMsg, what is a problem with that
DeleteIts working and not working,
ReplyDeleteIts working among others to show file chooser, but it's not working , the result from camera return nothing
I user galaxy m20 android 10
Is it createImageFile function failed ?
https://youtu.be/Nt0g2o8aklA
DeleteHi madam,
ReplyDeleteYour the best, Your Tutorials and Code Providing a good platform for people like us, stay blessed. I wanna mention one thing in few comments they mentioned the camera issue the problem is that "The upload wasn't working at all after Google WebView update" Present I'm trying to find code to resolve the issue and madam if you can find the solution means it would be helpful.
Thank You and Best Regards!
https://youtu.be/Nt0g2o8aklA
Deleteit worked seamlessly
ReplyDeleteCan I upload any file type? like pdf, mp4 and so on?
ReplyDeletehttps://youtu.be/Nt0g2o8aklA
DeleteI want a code only for file upload in webveiw not from camera. File may be pdf, doc etc. Please make a video for this, there is not enough and good video for this on youtube.
ReplyDeletehttps://youtu.be/Nt0g2o8aklA
Deleteeverything is working fine, but image from camera is saving, and when i click on pdf file link or gdrive link in webview, no response from app
ReplyDeletehttps://youtu.be/Nt0g2o8aklA
DeleteThe video was very good, it helped me a lot. Thank you. My web application loads pdf in the same option. you have a similar video on how to upload the pdf?.
ReplyDeleteI need it too. If you have figured out something then please let me know.
Deletehttps://youtu.be/Nt0g2o8aklA
DeleteAssalamualaikum. it's working. thank you very much. but I have any little problem just little problem, when I take picture from my camera, I don't see file name on my file choosen web. so my picture can't be upload because is empty. can you help it?
ReplyDeletebut if I choose file on my file, it's working and I can upload very well. Thanks
https://youtu.be/Nt0g2o8aklA
Deletethanks.., you save my time
ReplyDeleteThank you soo much for this amazing tutorial... Will you please make a video on how to upload video file...
ReplyDeletehttps://youtu.be/Nt0g2o8aklA
Deletehi thanks first of all for making this great tutorial series i have the same issue gallery work fine but camera uploads not working i copy and paste code as per video directions and do it 4th times also allow permissions to camera but issue is there please guide the solution thanks
ReplyDeleteFollow my this video, your problem is solved in this video. Video Link: https://youtu.be/Nt0g2o8aklA
Deletecamera opens and after taking picture its not do anything on press ok
ReplyDeletehttps://youtu.be/Nt0g2o8aklA
DeleteHi, a code like this worked since android 10. When the app runs on android 10 onShowFileChooser is not called at all.
ReplyDeleteDo you have any idea or a workaround ?
Hi, this works before android 10. If the app is running on android 10 the method "onShowFileChooser" is not called at all.
ReplyDeleteDo you know any workaround ?
Thanks
https://youtu.be/Nt0g2o8aklA
DeleteThank you, this is nice tutorial, it's worked!
ReplyDeleteHi Bro. May I know how to enable customer current location
ReplyDeletethanks so much for your help :-)
ReplyDeletethanks so much for your help
ReplyDeleteI don't no your language but i understand. I really hard to search, time god. keep it up and great job thanks
ReplyDeletehttps://youtu.be/Nt0g2o8aklA
DeleteHi, my website makes call through browser and connects to whats-app, how can I activate both through webview ?
ReplyDeleteHow can use code for upload with download support. Here you guided for upload file only and for download in previous tutorial. When I used code for download and after that used the above codes for upload, there are errors of some code already used.
ReplyDeletehttps://youtu.be/Nt0g2o8aklA
Deletewhen i click on choose file, and after click cancel and once again i try to click on choose file it doesnot open
ReplyDeleteplease help me out
After your complain, I have checked multiple times , but I saw it's working perfectly, please check your code again.
Deletehttps://youtu.be/Nt0g2o8aklA
Deletewhat if we want to upload other format such as pdf, documents ?
ReplyDeleteimage upload is working fine but i cannot upload any other files
https://youtu.be/Nt0g2o8aklA
DeleteHow to Maintain PHP Login Logout Session ? Please Help me
ReplyDeleteHi, it worked but I can't select more that one file. I can only pick one image file at a time yet I really want to be able to select multiple files at a time. Any help will really be helpful
ReplyDeletehttps://youtu.be/Nt0g2o8aklA
DeleteThanks. You are awesome.
ReplyDeleteafter capturing with camera file not selecting in input this is only in android 11 please can u check once and tell me
ReplyDeleteIf this method is not working for you, then you can follow my another method. Here is the link: https://weblearners.blogspot.com/2021/06/how-to-enable-video-image-and-file-upload-in-android-webview-app.html
Deletestill says
ReplyDeleteerror: cannot find symbol
private ValueCallback mUploadMessage;
^
symbol: class uri
location: class MainActivity
Thanks a lot for this post,
ReplyDeleteCan I know how to remove camera option from this?
Bcz I only need document choosing method.
Any way this post was very very helpful to me so Thank you again 🤝🤍🤍🤍
Thank u
ReplyDeleteIn my case uploading is working fine but in case i call this function along with onCreateWindow, onCreateWindow method is working fine but file uploading option does not working, kindly help me.
ReplyDelete