Git Product home page Git Product logo

android-smartwebview's Introduction

Android Smart WebView

alt text alt text MIT Licence

GETTING STARTED · PLUGINS · DOCUMENTATION · ISSUES

SWV is a framework built on Java to develop advanced hybrid webview applications with ease.

A small build with features working out of the box: Live GPS Location, Notifications with FCM, AdMob, Chrome Tabs, Process Camera Input, Upload/Download Files, Custom Rating System, Multiple User Interfaces and more.

Table of Contents

Getting Started

These instructions will help you get your Smart WebView copy up and running on your local machine for development and testing purposes.

YouTube Playlist - Getting Started with Smart WebView

Prerequisites

Project was built on Android Studio and requires minimum Android API 21+ (5.0 Lollipop) SDK to test run.

Setup

  1. Download repo or clone the project

    git clone https://github.com/mgks/Android-SmartWebView

  2. Download google-services.json file from Firebase (instructions)

  3. Load project in Android Studio

    File > Open > Browse to Project and Select

  4. Let Android Studio process the project and download support libraries and dependencies

  5. Just to make sure, try cleaning and rebuilding project before run

    Build > Clean Project then Build > Rebuild Project

  6. Got any error? You better fasten you seatbelt. It's going be a bumpy night.

Configurations

For detailed configuration, check project Documentation.

Device Permissions

You can remove any of the following requests if you do not need them, you can also disable features with permission variables. For default setup, following permissions are required.

INTERNET
ACCESS_NETWORK_STATE
ACCESS_WIFI_STATE
WRITE_EXTERNAL_STORAGE
READ_EXTERNAL_STORAGE
CAMERA
ACCESS_FINE_LOCATION
VIBRATE
c2dm.permission.RECEIVE
hardware.location.gps
hardware.touchscreen

INTERNET permission is required for any webview to work.

WRITE_EXTERNAL_STORAGE is required for camera file processing: if you have ASWP_FUPLOAD and ASWP_CAMUPLOAD enabled to upload image/video files.

Config Variables

Complete webpage URL or load local file as file:///android_res/dir/file.html

ASWV_URL   = "https://github.com/mgks"   // domain or directory or address to any root file

Permission Variables

ASWP_JSCRIPT     = true     // enable JavaScript for webview
ASWP_FUPLOAD     = true     // upload files from local device
ASWP_MULFILE     = true     // upload multiple files
ASWP_CAMUPLOAD   = true     // enable camera file upload
ASWP_ONLYCAM     = false    // incase you want only camera for input files

ASWP_LOCATION    = true     // track GPS locations

ASWP_RATINGS     = true     // show ratings dialog; auto configured, edit method get_rating() for customizations
ASWP_PULLFRESH   = true     // pull to refresh feature
ASWP_PBAR        = true     // show progress bar
ASWP_ZOOM        = false    // zoom control for webpages
ASWP_SFORM       = false    // save form data and auto-fill information
ASWP_OFFLINE     = false    // whether the loading webpages are offline or online
ASWP_EXTURL      = true     // open external url with default browser instead of app webview

ASWP_TAB         = true;    // instead of default browser, open external URLs in chrome tab
ASWP_ADMOB       = false;   // enabled Google AdMob

Security Variables

ASWP_CERT_VERIFICATION   = true   // verify whether HTTPS port needs certificate verification

Other Variables

ASWV_ORIENTATION = 0;   // change device orientation to portrait (1)(default) or landscape (2) or unspecified (0)

ASWV_LAYOUT      = 0;   // default=0; for clear fullscreen layout and 1 to add drawer and navigation bar

// custom settings if layout `1` with search bar is set.
ASWV_SEARCH      = "https://www.google.com/search?q=";   // search query will start by the end of the present string

ASWV_SHARE_URL   = ASWV_URL+"?share=";   // URL where you process external content shared with the app
ASWV_EXC_LIST    = "";                   // domains allowed to be opened inside webview, separate domains with a comma (,)

ASWV_ADMOB       = "ca-app-pub-9276682923792397~7957851075";   // your unique publishers ID; this one is temporary

ASWV_F_TYPE      = "*/*"   // use `image/*` for image files only; check file type references for custom file type

POSTFIX_USER_AGENT      = true;     // set to true to append USER_AGENT_POSTFIX to user agent
OVERRIDE_USER_AGENT     = false;    // set to true to use USER_AGENT instead of default one
USER_AGENT_POSTFIX      = "SWVAndroid";    // useful for identifying traffic, e.g. in Google Analytics
CUSTOM_USER_AGENT       = "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36";    // custom user-agent

Features

GPS Location

If ASWP_LOCATION = true then the app will start requesting GPS locations of the device on regular basis and all of the recorded data will be sent to the webpage in form of cookies, with updated live GPS locations.

COOKIE "lat" for latitude
COOKIE "long" for longitude

Camera Input

You can either select to get input from both file manager and camera or can just choose camera to get image/video input. To get video input, add file type condition in your html input video/* and image/* for camera photos. By default ASWV_F_TYPE is set to */* and suggested not to change instead file type should be provided on web pages end.

Firebase Messaging

You need a firebase account to get started then download google-services.json and put it in the app level directory. Then you can create a POST request as below. See detailed steps to download firebase config file.

To URL: https://fcm.googleapis.com/fcm/send

Header:

content-type:application/json
authorization:key=____server_key_here___ (Firebase > Settings > Cloud Messaging)

Data:

{ "notification": {
    "title": "___title_string___",
    "text": "___text_string___",
     "click_action": "Open_URI"
  },
    "data": {
    "uri": "___the_URL_where_you_want_users_to_send__"
    },
  "to" : "___user_token___"
}

You can get ___user_token___ from COOKIE fcm_token.

Google AdMob

Enable ASWP_ADMOB to show ads, and get your App ID from AdMob to replace ASWV_ADMOB.

Chrome Tab

With ASWP_TAB you handle external links to be opened in the chrome tab or external browser. More chrome tab customizations are available inside MainActivity.

Content Sharing

User can share external content with your app like text, link or image. You can received data on your end by proving ASWV_SHARE_URL, an endpoint that can handle such requests. You can disable it by removing .ShareActivity from Manifest.

User Interfaces

You can switch between clean and native interface with ASWV_LAYOUT where 0 represents full screen interface and 1 as a complete drawer layout with search option and navigation bar.

To customize drawer bar, you can look into onNavigationItemSelected() method in MainActivity and activity_main_drawer.xml for menu items.

Rating System

Rating dialogue is enabled by default and can be handled by ASWP_RATINGS.

ASWR_DAYS            = 3;           // after how many days of usage would you like to show the dialog
ASWR_TIMES           = 10;          // overall request launch times being ignored
ASWR_INTERVAL        = 2;           // reminding users to rate after days interval

Contributing

If you want to contribute to the project, you're most welcome to do so. Just:

  • Fork it
  • Create your feature branch git checkout -b my-new-feature
  • Commit your changes git commit -am 'Added some feature'
  • Push to the branch git push origin my-new-feature
  • Create new Pull Request

Support the Project

There are few ways to support this project -

GitHub Sponsors: Support this project and my other works by becoming a GitHub sponsor. Means a lot :)

Get Smart WebView Pro: You can support this project by getting a Pro variant of SWV also with additional features and plugins, some of the features/plugins include - PQL, Google Login, Vision API, and QR/Barcode Reader.

Join Discussions: Feedbacks have helped this project become what it is today, share your honest feedback via Discussion Board, Email or report your project Issues here.

Follow Me on GitHub | Add Project to Watchlist | Star the Project

Known Bugs

...

Check Issues tab for more.

License

This project is published under the MIT License - see LICENSE file for details or read MIT license.

Acknowledgements

Thanks to other contributers who helped make this project amazing.

Closing Note

This project was initially developed by Ghazi Khan, but coming this far wouldn't be possible without the people who contributed to this project.

For development consulting or other support. Contact me!

A personal suggestion: You all must keep up with programming. It's sometimes difficult and sometimes easy but fun afterall, you can create your own world with programming and that's the beauty of it. So, all the best for your next creation.

Profile

android-smartwebview's People

Contributors

akhyariz avatar beiyanyunyi avatar es-que avatar hongwen000 avatar mgks avatar pauln avatar saeedesfandi avatar starman1108 avatar timhj avatar will-ks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-smartwebview's Issues

when I build the app it sho me following errors.

i amusing android studio 3.1.2 and force to change androidTestCompile to androidTestimplementation

Could not find method androidTestimplementation() for arguments [com.android.support.test.espresso:espresso-core:2.2.2, build_dgz0z00s1zugz2h20notdwp5n$_run_closure2$_closure7@3ece0eea] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Open File

Multiload

Multiload - Tell me, is it possible to implement this in order to download multiple files at the same time?

How to force open front camera for file upload

I've tried all these:
takePictureIntent.putExtra("android.intent.extras.CAMERA_FACING", android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT); takePictureIntent.putExtra("android.intent.extras.LENS_FACING_FRONT", 1); takePictureIntent.putExtra("android.intent.extra.USE_FRONT_CAMERA", true); takePictureIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);

Message checker

Great code! Thanks. I have a question. Can you customize your code for me so that the app runs in background and every 5 minutes sends a request to the server (together with webview cookies) to check for new messages? If there are new messages they must appear as notifications with sound y/o vibration and link to the app? If yes, tell me your price for this.

Great Job! I am just having 1 issue

Hello,

I love what you have done here. I am just having one issue...

When I put my PAGE URL in, the it freezes my page on load, no links, or js works... But when I put my homepage in, I can browse to the same page url and everything works perfect... I tried substituting my domain in for the domain variable and it did nothing. I though maybe it was the ".html" on the end of the URL, so I did a rerwite without it, and still no change. I noticed a lot of functions that use ASWV_URL and ASWV_HOST... I am busy trying to debug it, but if you have any direction, I would appreciate it. Ty

Upload image via Camera + resize

Hi,

I am using the Camera to capture and upload image, I wanted to resize the image before upload, how can this be done.

thanks

changing permission request to later + My Contribution :)

First and foremost, THANK YOU for providing this.

Currently, when I start the app, it'll ask for permission to access files. Due to the following line in onCreate:

if (ASWP_FUPLOAD) {
                if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                    ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 2);
                }
}

This doesn't make sense unless the app's entire purpose is to upload files. Otherwise, it'll confuse the user as to why the app is asking for permission. is it possible to move this request to After the user clicks Browse in an upload form?


And here is my tiny contribution, which will help the shouldOverrideUrlLoading method work on both new as well as old SDKs

//Overriding webview URLs
		@SuppressWarnings("deprecation")
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            boolean a = true;

           *******
        }

		@TargetApi(Build.VERSION_CODES.N)
		@Override
		public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
			String url = request.getUrl().toString();
            boolean a = true;
			*******
		}

File chooser display a Camera even if ASWP_CAMUPLOAD is false

Code change suggestion :
REPLACE
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (ASWP_CAMUPLOAD) {
BY
Intent takePictureIntent = null;
if (ASWP_CAMUPLOAD) {
takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

OTHERWISE THE TEST
if (takePictureIntent != null)
IS A NON SENSE.

Samsung Galaxy Tab 4 7.0 SM-T231

Samsung Galaxy Tab 4 7.0 SM-T231 - Prompt when the application starts on this device appears only white screen, how can I fix it?

05-10 09:07:19.752 2614-2614/mgks.os.webview E/EGL_emulation: tid 2614: eglSurfaceAttrib(1199): error 0x3009 (EGL_BAD_MATCH)
05-10 09:07:24.592 2614-2614/mgks.os.webview E/dalvikvm: Could not find class 'android.app.ActivityManager$TaskDescription', referenced from method mgks.os.webview.MainActivity.onResume
05-10 09:07:24.632 2614-2614/mgks.os.webview E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
05-10 09:07:24.762 2614-2614/mgks.os.webview E/EGL_emulation: tid 2614: eglSurfaceAttrib(1199): error 0x3009 (EGL_BAD_MATCH)

Cookie

Hello,
Jen'arrive not to recover the cookies on my web page created by the webview like for example cookie "lat" and "long".

I do this with js:
function listCookies() {
var theCookies = document.cookie.split(';');
var aString = '';
for (var i = 1 ; i <= theCookies.length; i++) {
aString += i + ' ' + theCookies[i-1] + "\n";
}
document.write("

"+aString+"

");
return aString;
}

Do you have an idea ? Why are my cookies not found?

Navigation

When accessing a link the android asks through which application to open. How do I navigate in the same window?

google Play Submission

Hi!
I am a new guy and learning about developing apps.
I came to know google is too hard to developers since it suspends app without any information.
Can you please guide me about it?

Thank U!

I asked you because I decided to use your template.

Requires media router 25.2.0 - Can't compile

I get the following error in the build.gradle file for the app module... I can't for the life of me find where mediarouter-v7:25.2.0 is being included though?

"All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 27.1.1, 25.2.0. Examples include com.android.support:animated-vector-drawable:27.1.1 and com.android.support:mediarouter-v7:25.2.0"

Page reloads every time app is resumed

Hi, awesome work on this, I'm loving it. I just have one issue, any time the application is left and then resumed (eg. press home and relaunch the app), it does not resume to where it was before; instead it shows the splash screen again and reloads the first page. Is there any way to maintain the current loaded page and not reload?

java.io.IOException: Permission denied at java.io.File.createTempFile

Hi! Congrats on your work!
I have one problem using the capture feature, to open the native camera. After giving the permission for using the camera, I get always java.io.IOException: Permission denied, so the only intent launched in the capture input is the file chooser.
What I'm ding wrong?

Here is a stacktrce:

                                                                             java.io.IOException: Permission denied
                                                                                 at java.io.UnixFileSystem.createFileExclusively0(Native Method)
                                                                                 at java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:280)
                                                                                 at java.io.File.createNewFile(File.java:948)
                                                                                 at java.io.File.createTempFile(File.java:1862)

Thanks

Fabian

Showing No internet on clicking a specific button

This repo is very helpful to me but there is a issue.
When i am clicking on a button which is redirecting me to a folder in my web root, it showing NO INTERNET CONNECTION. While there are some more button of like this they are working properly.
On accessing through browser it is working fine. I am unable to get the problem.
Thanks in advance

App says no internet or slow internet once logged in

screenshot 20

Happens on the emulator and on my galaxy note 8. On wifi and cell internet. I have plenty of mb/s, 200+. I don't know if it is the app, but my site works fine any other way when I access. Any help would be appreciated.

Chris

Splash Screen

Thank you for the great script! It's perfect for my project. You have done a great job! And thank you for sharing with us!
I'm having trouble with removing the splash screen. I couldn't find anything about it in the documentation.
Could you please help me out? Thanks in advance!

Image upload

Hi,

How can I upload multiple images from media library?

Music site

Tell me, if I build a music site in the application, when will I turn it off, will it play music?

facebook share from webview

Hi, my app is like a newspaper, and articles have simple links to share on facebook and other social networks. When I click on the share on facebook button, it opens Facebook on a browser, does not try to use native Facebook app. Is there a way to intercept that link and open the facebook app with the link to share? maybe using facebook sdk? sorry Im so new on android dev...

Plus go back to my app afterwards.

Javascript, Jquery Functions, Onclick

Hi
i would like to thank you so much for the great job and share with us.

My the app is a mobile responsive website, but when i opened inside the project, my jquery and javascript functions stops.
The variable to enable the javascrit is true, but still not working. Do you have idea what can be?
Thank you very much!

Take screenshot from HTML Web Page

Hi, it is possible to take a screenshot in the SmartWebView?
I use this javascript code on android and it works with any browser.
<script> $(document).ready(function () { $('#save_image_locally').click(function () { document.getElementById("save_image_locally").style.visibility="hidden"; html2canvas($('#mydiv'), { onrendered: function (canvas) { var a = $("<a>").attr("href", canvas.toDataURL('image/png')) .attr("download", "xxx.png") .appendTo("body"); a[0].click(); a.remove(); document.getElementById("save_image_locally").style.visibility="visible"; } }); }); }); </script>
How can I implement it in the SmartWebView?

What if phone doesn't have external SD card?

I am getting the error

Image file creation failed
java.io.IOException: open failed: ENOENT (No such file or directory)
at java.io.File.createNewFile(File.java:939)
at java.io.File.createTempFile(File.java:1004)
at MainActivity.create_image(MainActivity.java:507)

on line 507 the code is

File sd_directory   = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
return File.createTempFile(new_name, ".jpg", sd_directory);

My phone doesn't have external storage card.

Multiple files

Dear sir...
Great Job thanks for making the project open source...
I read the documentation to see how to enable multiple files ...
I made the variable true ...
Then i tested it ...
The problem is i select multiple files but in the page appear that i select one file...???

Upload Camera File - 0 Bytes

first, thank you very much for your work.
I have a problem in which it consists of uploading images with the camera.
taking a picture with the camera and upload.
it shows: name, ext, but with size of "0" bytes and it keeps a corrupt image. :(

The method of file browser works perfectly! :)

Real Cell phones used for test:

  • Samsung S5 (not working upload camera and file browser working)
  • Samsung S6 (not working upload camera and file browser working)
  • Samsung S7 (not working upload camera and file browser working)
  • LG K410G Android 5.0.2 (working camera and file browser)

With emulador:
Emulador Android Native: Upload from camera and file archive it works perfectly.
Is it just a problem with the samsungs?

PD: Sorry for me english, translation by google.

screenshot_20180927-174344
screenshot_20180927-174413

Something went wrong issue

Hello,

I have external links within my app, and when I click those links, I get that notification saying Something went wrong. Also, the page displays this message:

net::ERR_NOT_FOUND or something like that

Any idea what may be causing this?

Litle title mistake

In MainActivity.java I suspect :
case 2:
builder.setTicker(getString(R.string.app_name));
builder.setContentTitle(getString(R.string.app_name));
should be
case 2:
builder.setTicker(getString(R.string.app_name));
builder.setContentTitle(getString(R.string.loc_perm));

Error showing on opening another local file

Hello.
Thank you for your SmartWebView Code.

I have an error coming in my webview.

i am using local html file for my project
"file:///android_asset/www/index.html"

I am redirecting the user to login.html file if not logged in.
but i am getting an error toast as "Cannot display PDF (login.html cannot be opened)"​

Please let me know how to handle navigation.

Enable javascript

Hi @mgks im trying to run the app but im finding a javascript block.
Please help me on this.
khan

Location error message

I have enabled geolocation. If a user with location activated on his device uses the app there is no problem, but if the user has disabled geolocation on android settings, the prompt will show everytime the user navigates to another page of the web inside the webview.

ASWP_CAMUPLOAD

Everything is working fine.
Thank you for this great project.
I just have an issue managing the CAM_UPLOAD.

I can't find how to set the camera as default to upload an image. When i hit the button to upload an image, it opens the file manager.

I had set ASWP_FUPLOAD and ASWP_CAMUPLOAD as true, and in my html file I use this tag to select an image ""

How can I set the camera as the default, or olny option for upload images?

Thank you in advance.

Project work

Will you be engaged in a project or can you consider it dead? There is almost no activity.

WBRTC and MEDIA stream

Hi
Than ks for making this project . i came here since the popular crosswalk web view is depreciated witch had a plugin with cordova , i am trying to use WEB-RTC with media streaming and recording options , does Android - smart web view support it ?

Any plans for 8.0 API 26 Support?

Notifications and permission changed, also the upload doesn't work when taking picture directly from the camera to a .

I've been using for a while it now and works wonders till API 25.

My question is should I update the code? Or do you have some WIP ?

Thanks for the amazing app.

accept="image/*" capture=environment

This app supports
<input type="file" name="image" accept="image/*" capture="user"> ?
Because the app previously i was using is not working.

Please clarify me. Thankyou

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.