Skip to content

Latest commit

 

History

History
279 lines (209 loc) · 11.7 KB

README-ENGLISH.md

File metadata and controls

279 lines (209 loc) · 11.7 KB

Introduction to AgentWeb

AgentWeb is an Android WebView based, extremely easy to use and powerful library. Please refer to Sample above for detailed usage.

AgentWeb Sample Download

AgentWeb Sample shows AgentWeb library powerful features, detailed link, please click the download experience

download

  • Gradle

     api 'com.just.agentweb:agentweb:4.1.2' // (Required)
     api 'com.just.agentweb:filechooser:4.1.2'// (optional)
     api 'com.download.library:Downloader:4.1.2'// (optional)
    

use

Common use

mAgentWeb = AgentWeb.with(this)//传入Activity or Fragment
                .setAgentWebParent(mLinearLayout, new LinearLayout.LayoutParams(-1, -1))//Incoming AgentWeb parent control, if the parent control is RelativeLayout, then the second parameter needs to be passed RelativeLayout.LayoutParams, the first parameter and the second parameter should correspond.
                .useDefaultIndicator()// use the default onProgress bar
                .defaultProgressBarColor() // Use default onProgress bar color
                .setReceivedTitleCallback(mCallback) //Set the Web page title callback
                .createAgentWeb()//
                .ready()
                .go("http://www.jd.com");

renderings

  • call Javascript method stitching too much trouble? Please see.

// Javascript method
Function callByAndroid () {
      Console.log ("callByAndroid")
  }
// Android end
MAgentWeb.getJsEntraceAccess (). QuickCallJs ("callByAndroid");
//onResult
ConsoleMessage: callByAndroid lineNumber: 27
  • Javascript call Java

// Android side, AndroidInterface is an injection class, which has a no parameter method: callAndroid
AddjavaObject ("android", new AndroidInterface (mAgentWeb, this));
/ / In Js will be able to pass
Window.android.callAndroid () / / call the Java layer AndroidInterface class callAndroid method
  • event handling

@Override
		Public boolean onKeyDown (int keyCode, KeyEvent event) {
        If (mAgentWeb.handleKeyEvent (keyCode, event)) {
            Return true;
        }
        Return super.onKeyDown (keyCode, event);
    }	
  • Follow the Activity Or Fragment life cycle, the release of CPU more power.

	@Override
    Protected void onPause () {
        MAgentWeb.getWebLifeCycle (). OnPause ();
        Super.onPause ();

    }

    @Override
    Protected void onResume () {
        MAgentWeb.getWebLifeCycle (). OnResume ();
        Super.onResume ();
    }
  • full screen video playback

<! - If your application needs to use the video, then please use the AgentWeb Activity corresponding to the list file to add the following configuration ->
Android: hardwareAccelerated = "true"
Android: configChanges = "orientation | screenSize"
  • positioning

<! - AgentWeb is the default boot location, please add the following permissions in your AndroidManifest file. ->
    <Uses-permission android: name = "android.permission.ACCESS_FINE_LOCATION" />
    <Uses-permission android: name = "android.permission.ACCESS_COARSE_LOCATION" />
  • WebChromeClient Or WebViewClient handles business logic

// AgentWeb maintains the use of WebView,
MAgentWeb = AgentWeb.with (this) //
                .setAgentWebParent (mLinearLayout, new LinearLayout.LayoutParams (-1, -1)) //
                .useDefaultIndicator () //
                .defaultProgressBarColor ()
                .setReceivedTitleCallback (mCallback)
                .setWebChromeClient (mWebChromeClient)
                .setWebViewClient (mWebViewClient)
                .setSecutityType (AgentWeb.SecurityType.strict)
                .createAgentWeb () //
                .ready ()
                .go (getUrl ());
// WebViewClient
Private WebViewClient mWebViewClient = new WebViewClient () {
        @Override
        Public void onPageStarted (WebView view, String url, Bitmap favicon) {
           // do you work
        }
    };
    // WebChromeClient
    Private WebChromeClient mWebChromeClient = new WebChromeClient () {
        @Override
        Public void onProgressChanged (WebView view, int newProgress) {
            // do you work
        }
    };
  • Get WebView

 WebView mWebView = mAgentWeb.getWebCreator (). Get ();
  • Sync cookies

AgentWebConfig.syncCookies ("http://www.jd.com", "ID = XXXX")
  • MiddleWareWebChromeBase supports multiple WebChromeClients

// Slightly, please see Sample
  • MiddleWareWebClientBase supports multiple WebViewClient

// Slightly, please see Sample
  • View Cookies

String cookies = AgentWebConfig.getCookiesByUrl (targetUrl);
  • AgentWeb Complete use

mAgentWeb = AgentWeb.with (this) //
                .setAgentWebParent ((LinearLayout) view, new LinearLayout.LayoutParams (-1, -1)) // The AgentWeb parent passed in.
                .setIndicatorColorWithHeight (-1, 2) / / Set the color and height of the onProgress bar, -1 is the default value, the height is 2, the unit is dp.
                .setAgentWebWebSettings (getSettings ()) // Set AgentWebSettings.
                .setWebViewClient (mWebViewClient) // WebViewClient, same as WebView, but do not get WebView calling setWebViewClient (xx) method, which will override AgentWeb DefaultWebClient and the corresponding middleware will also fail.
                .setWebChromeClient (mWebChromeClient) // WebChromeClient
                .setPermissionInterceptor (mPermissionInterceptor) / / permission to intercept 2.0.0 join.
                .setReceivedTitleCallback (mCallback) // Title callback.
                . SetSecurityType (AgentWeb.SecurityType.strict) / / strict mode Android 4.2.2 The following will give up the injection of the object, use AgentWebView did not affect.
                .addDownLoadResultListener (mDownloadListener) // Download callback
                .setAgentWebUIController (new UIController (getActivity ())) // Custom UI AgentWeb3.0.0 join.
                .setMainFrameErrorView (R.layout.agentweb_error_page, -1) / / Parameter 1 is the layout of the onResult display, parameter 2 Click refresh control ID -1 Click to refresh the entire layout Click AgentWeb 3.0.0 to join.
                .useMiddleWareWebChrome (getMiddleWareWebChrome ()) // Set up WebChromeClient middleware, support multiple WebChromeClient, AgentWeb 3.0.0 join.
                .useMiddleWareWebClient (getMiddleWareWebClient ()) / / Set WebViewClient middleware, support multiple WebViewClient, AgentWeb 3.0.0 join.
                . OpenParallelDownload () / / open parallel download, the default serial download.
                .setNotifyIcon (R.mipmap.download) // Download notification icon.
                .setOpenOtherPageWays (DefaultWebClient.OpenOtherPageWays.ASK) / / open other pages, the pop-up query users to other applications AgentWeb 3.0.0 to join.
                .interceptUnkownScheme () / / Interception Scheme AgentWeb 3.0.0 can not find the relevant page to join.
                .createAgentWeb () // Create AgentWeb.
                .ready () / / Set WebSettings.
                .go (getUrl ()); // WebView Load and display the URL page.

Precautions

  • Alipay need to use the introduction of Alipay SDK, and dependent on the project, WeChat payment do not need to do any operation.
  • AgentWeb‘s internal use of AlertDialog depends on the AppCompat theme.
  • setAgentWebParent does not support ConstraintLayout.
  • mAgentWeb.getWebLifeCycle (). onPause (); Will pause all WebView in the application.
  • minSdkVersion 16 or less Customize WebView Please be aware of communication safety with JS.

ProGuard rules

If your project needs to be proguard , please add the following configuration

-keep class com.just.agentweb.** {
    *;
}
-dontwarn com.just.agentweb.**

Java injection class do not proguard, such as sample inside the AndroidInterface class, need Keep.

-keepclassmembers class com.just.library.agentweb.AndroidInterface {*;}

Thank you

have questions or have better suggestions

about me

An Android developer located in Shenzhen, if you have a better job offer available to me, please contact Email: [email protected]

Play reward

If you like the design of AgentWeb, you can invite the author to have a cup of coffee.

AgentWeb

AgentWeb is a WebView completely out of the Act, from the Activity, Fragment xml layout, independent of the Android Web library.

Finally, if the library is helpful to you, I may be grateful to the top right corner of my support, thanks! Of course, I prefer you to become a contributor to Fork PR. AgentWeb

License

License

Copyright (C)  Justson(https://github.com/Justson/AgentWeb)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.