CN110275730A - A kind of method and device based on Android platform JavaScript customization serviceization - Google Patents

A kind of method and device based on Android platform JavaScript customization serviceization Download PDF

Info

Publication number
CN110275730A
CN110275730A CN201910452883.2A CN201910452883A CN110275730A CN 110275730 A CN110275730 A CN 110275730A CN 201910452883 A CN201910452883 A CN 201910452883A CN 110275730 A CN110275730 A CN 110275730A
Authority
CN
China
Prior art keywords
service
customization
javascript
webview
adjusted
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201910452883.2A
Other languages
Chinese (zh)
Inventor
王锐旭
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangzhou Joiway Information Science & Technology Co Ltd
Original Assignee
Guangzhou Joiway Information Science & Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangzhou Joiway Information Science & Technology Co Ltd filed Critical Guangzhou Joiway Information Science & Technology Co Ltd
Priority to CN201910452883.2A priority Critical patent/CN110275730A/en
Publication of CN110275730A publication Critical patent/CN110275730A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The present invention provides a kind of method and devices based on Android platform JavaScript customization serviceization, belong to Android development technique field.The present invention provides a kind of method and devices based on Android platform JavaScript customization serviceization, various correlation techniques in flexible Application JavaScript and Webviwe, and the device of modular unit, it realizes through serviceization technology, JavaScript is allowed to obtain more primary platform features;It realizes customization serviceization, allows service to realize simple, customized height is reusable.

Description

A kind of method and device based on Android platform JavaScript customization serviceization
Technical field
The present invention relates to Android Webview and JavaScript interaction technique field, more particularly to one kind are flat based on Android The method and device of platform JavaScript customization serviceization.
Background technique
Android Webview and JavaScript interaction refer to and show mobile phone web pages in Android exploitation Webview, is related to The interaction of the primary development language and webpage JavaScript that arrive.Webpage and the communication of app can be got through very well, allow webpage development energy Obtain more primary services.Such as Taobao, wechat etc..The technology mainly used has JSBridge.However, Webview and JavaScript interaction is not carried out serviceization in Android exploitation, so that exploitation is complicated, code redundancy.How to realize and passes through clothes Businessization technology allows JavaScript to obtain more primary platform features;How to realize customization serviceization, service is allowed to realize letter Single, customized height is reusable.It is badly in need of a kind of method and device based on Android platform JavaScript customization serviceization, To overcome the deficiencies in the prior art.
Summary of the invention
It is an object of the present invention to provide a kind of methods and dress based on Android platform JavaScript customization serviceization It sets, allows webpage development that can obtain more primary services, overcome the deficiencies in the prior art, realize customization serviceization, so that Develop uncomplicated, code not redundancy.
Technical scheme is as follows:
A method of serviceization being customized based on Android platform JavaScript, which is characterized in that comprise the steps of:
1) customization service is write, the customization service defines service moulding plate by the abstract method of Java interface, makes by oneself Justice service Similar integral interface, the method for rewriteeing the interface realize customized method of servicing, inherit the customized Webview of rewriting, In customized Webview initialization, defines a Map collection class member variable and store customized service class object and Service name Claim, arrives the customized service class set toward customized Webview registration by the above process;
2) write custom protocol, the custom protocol by JavaScript transmitting Service name and parameter assembling and At;
3) it initiates service request custom protocol and gives Android Webview;
4) judge whether it is custom protocol described in step 2), the judgement is passed through by Android Webview WebviewClient monitors the callback method shouldOverrideUrlLoading judgement of the inside;
5) if so, transmitting custom protocol is parsed to protocol analysis transponder;If it is not, it is silent then to give Webview Recognize processing mode, end operation;
6) the corresponding customization service of custom protocol has been adjusted in reflection;
7) judge whether that customization has been adjusted to service successfully;
If 8) customization has been adjusted to service the service successfully customized inside service processing, the internal services are editor's generations The service that code is handled and is packaged into (such as: positioning obtains system information);Protocol analysis transponder readjustment processing Success parameter knot Fruit;If having adjusted customization service unsuccessful, protocol analysis transponder adjusts back processing failure parametric results;
9) result of parameter passes to JavaScript, and the result of the parameter passes through webview method loadUrl (jsCallback) injection js is adjusted back to JavaScript;
10) step 9) end operation afterwards is completed.
Further, the protocol analysis transponder in the step 4) is to parse to obtain Service name, readjustment side by Uri Method id, Transfer Parameters;
Further, the implementation method that the step 6) reflection has adjusted the corresponding customization of custom protocol to service is: association After view parsing transponder is parsed, by the service for obtaining the Service name registration service that Map collection class stores in step 1) Class object has adjusted the method for servicing of customization;If the service class pair is not found in the registration service of Map collection class storage As then being reflected by Java and obtaining the service class object of fixed packet under one's name, adjusted corresponding customization method of servicing.Further, The step 8) and step 9), implementation method getparms is: in the clothes that Android java class processing JavaScript tune rises The result of processing, is passed to JavaScript by loadUrl (jsCallback) method of Webview, adjusted by business The callback method of JavaScript.
It is a kind of based on Android platform JavaScript customization serviceization device, characterized by comprising:
Ginseng protocol element is passed, custom protocol is passed into ginseng to Webview for JavaScript;First judging unit is used In judging whether it is defined custom protocol;
Resolution unit obtains Transfer Parameters for parsing custom protocol;
Unit has been adjusted in reflection, has adjusted the corresponding customization service of custom protocol for reflecting;
Second judgment unit has adjusted customization to service successfully for judging whether;
Unit is adjusted back, ginseng readjustment processing parameter knot is passed to JavaScript by protocol analysis transponder for Webview Fruit, specific implementation are to inject js by webview method loadUrl (jsCallback) to adjust back to JavaScript;
End unit is used for end operation.
The beneficial effects of the present invention are: allow JavaScript to obtain more primary platform features by serviceization technology, Enrich client customization function;The serviceization of customization allows service to realize simple, and customized height is reusable.
Detailed description of the invention
Fig. 1 is a kind of general frame for the method and device that serviceization is customized based on Android platform JavaScript of the present invention Structure chart
Fig. 2 is a kind of flow chart for the method and device that serviceization is customized based on Android platform JavaScript of the present invention
Fig. 3 is a kind of device connection of method and device that serviceization is customized based on Android platform JavaScript of the present invention Figure
Specific embodiment
The present invention is described further with reference to the accompanying drawing:
Embodiment one:
JavaScript customizes serviceization, realizes and JavaScript is extended more primary platform features, customized Platform feature do serviceization to be realized, to realize reusability at service one by one.For example Android client Webview is aobvious It during the web page operation shown, needs to customize good-looking smoothness, meets the customized pop-up of user experience, so that it may need to only write Corresponding customized pop-up is called in any scene as needed as service, JavaScript, improves user experience, and service is real It is now simple, it can reuse.The specific implementation steps are as follows:
1) the customization service comprising customized pop-up is write, the customization service passes through the abstract method of Java interface Service moulding plate, the customized service Similar integral interface are defined, the method for rewriteeing the interface realizes customized method of servicing, inherits Customized Webview is rewritten, in customized Webview initialization, it is customized to define a Map collection class member variable storage Class object and service name are serviced, arrives the customized service class set toward customized Webview registration by the above process;
2) JavaScript writes according to the needs for the customized pop-up for calling the step 1) in any scene and makes by oneself Adopted agreement;
3) it initiates service request custom protocol and gives Android Webview;
4) judge the callback method for monitoring the inside by WebviewClient by Android Webview ShouldOverrideUrlLoading judges whether it is the custom protocol in step 2);
5) if so, transmitting custom protocol is parsed to protocol analysis transponder;If it is not, it is silent then to give Webview Recognize processing mode, end operation;
6) the customization service of the corresponding customized pop-up of custom protocol has been adjusted in reflection;
7) judge whether that the customization for having adjusted customized pop-up services successfully;
If 8) adjusted the customization of customized pop-up to service successfully, by the service inside customization service processing, protocol analysis Transponder readjustment handles successfully parametric results, so that smooth realizes JavaScript in the web page operation that Webview is shown Customized pop-up service is called in any scene as needed;If having adjusted unsuccessful, the agreement solution of fixed customized pop-up uniform business It analyses transponder and adjusts back processing failure parametric results;
9) result of parameter passes to JavaScript, and the result of the parameter passes through webview method loadUrl (jsCallback) injection js is adjusted back to JavaScript;
10) step 9) end operation afterwards is completed, until subsequent operation judges that custom protocol has corresponding customization customized Pop-up service.
Embodiment two:
Android client terminal web page obtains position inaccurate by JavaScript, and simply the positioning function of Android can be made It for service, is supplied to JavaScript and is called in any desired scene, more accurate positioning, service is realized simply, can be repeated It utilizes.The specific implementation steps are as follows:
1) the customization service comprising calling Android positioning function is write, the customization service passes through the pumping of Java interface As method defines service moulding plate, the customized service Similar integral interface, the method for rewriteeing the interface realizes customized service side Method is inherited and rewrites customized Webview, in customized Webview initialization, defines a Map collection class member variable storage Customized service class object and service name are deposited, arrives the customized service class toward customized Webview registration by the above process Set;
2) JavaScript needs to compile according to the calling Android positioning function for calling the step 1) in any scene Write custom protocol;
3) it initiates service request custom protocol and gives Android Webview;
4) judge the callback method for monitoring the inside by WebviewClient by Android Webview ShouldOverrideUrlLoading judges whether it is the custom protocol in step 2);
5) if so, transmitting custom protocol is parsed to protocol analysis transponder;If it is not, it is silent then to give Webview Recognize processing mode, end operation;
6) the corresponding customization service for calling Android positioning function of custom protocol has been adjusted in reflection;
7) judge whether that the customization for calling Android positioning function services successfully;
If 8) call the customization of Android positioning function to service successfully, by the service inside customization service processing, association View parsing transponder readjustment handles successfully parametric results, to realize that JavaScript calls Android fixed in any desired scene Bit function, more accurate positioning, service is realized simply, can be reused;If having adjusted fixed customized pop-up uniform business unsuccessful, Protocol analysis transponder adjusts back processing failure parametric results;
9) result of parameter passes to JavaScript, and the result of the parameter passes through webview method loadUrl (jsCallback) injection js is adjusted back to JavaScript;
10) step 9) end operation afterwards is completed, until subsequent operation judges that custom protocol has corresponding customization to call peace The service of tall and erect positioning function.
Embodiment three:
A kind of device based on Android platform JavaScript customization serviceization is, characterized by comprising: biography ginseng agreement list Unit, second judgment unit, readjustment unit, end unit have been adjusted in member, the first judging unit, resolution unit, reflection;
Ginseng protocol element is passed, custom protocol is passed into ginseng to Webview for JavaScript, specifically, initiating service Request custom protocol gives Android Webview;
First judging unit, for judging whether it is defined custom protocol, the judgement is led to by Android Webview Cross the callback method shouldOverrideUrlLoading judgement that WebviewClient monitors the inside;
Resolution unit obtains Transfer Parameters for parsing custom protocol;
Unit has been adjusted in reflection, has adjusted the corresponding customization service of custom protocol for reflecting, its implementation is: agreement solution After analysis transponder is parsed, by obtaining the service class object for the registration service that Service name is stored in Map collection class, it is fixed to have adjusted Method of servicing HybridService processed, the registration service as Map collection class stores do not have corresponding method, can be anti-by Java It penetrates and obtains the service class object of fixed packet under one's name, adjusted corresponding customization method of servicing;
Second judgment unit has adjusted customization to service successfully for judging whether;
Unit is adjusted back, ginseng readjustment processing parameter knot is passed to JavaScript by protocol analysis transponder for Webview Fruit, its implementation are: implementation method getparms is: the service that JavaScript tune rises is handled in Android java class, The result of processing passes to JavaScript by loadUrl (jsCallback) method of Webview, has adjusted JavaScript Callback method;
End unit is used for end operation.

Claims (5)

1. a kind of method based on Android platform JavaScript customization serviceization, which is characterized in that comprise the steps of:
1) customization service is write, the customization service defines service moulding plate, customized clothes by the abstract method of Java interface Business Similar integral interface, the method for rewriteeing the interface realize customized method of servicing.Rewrite customized Webview: customized When Webview is initialized, defines a Map collection class member variable and store customized service class object and service name, pass through The above-mentioned customized Webview process of rewriting, which is realized, registers customized service class set by customized Webview;
2) custom protocol is write, the custom protocol assembles transmitting Service name and parameter by JavaScript;
3) it initiates service request custom protocol and gives Android Webview;
4) judge whether it is custom protocol described in step 2), the judgement is passed through by Android Webview WebviewClient monitors the callback method shouldOverrideUrlLoading judgement of the inside;
5) if so, transmitting custom protocol is parsed to protocol analysis transponder;If it is not, then giving at Webview default Reason mode, end operation;
6) the corresponding customization service of custom protocol has been adjusted in reflection;
7) judge whether that customization has been adjusted to service successfully;
If 8) customization has been adjusted to service the service successfully customized inside service processing, protocol analysis transponder readjustment is handled successfully Parametric results;If having adjusted customization service unsuccessful, protocol analysis transponder adjusts back processing failure parametric results;
9) result of parameter passes to JavaScript, and the result of the parameter passes through webview method loadUrl (jsCallback) injection js is adjusted back to JavaScript;
10) step 9) end operation afterwards is completed.
2. a kind of method based on Android platform JavaScript customization serviceization as described in claim 1, which is characterized in that Protocol analysis transponder in the step 4) is to parse to obtain Service name, callback method id, Transfer Parameters by Uri.
3. a kind of method based on Android platform JavaScript customization serviceization as described in claim 1, which is characterized in that The implementation method that the step 6) reflection has adjusted the corresponding customization of custom protocol to service is: protocol analysis transponder has parsed Cheng Hou has adjusted the clothes of customization by obtaining the service class object of the Service name registration service that Map collection class stores in step 1) Business method;If the service class object is not found in the registration service of Map collection class storage, is reflected and obtained by Java The service class object of fixed packet under one's name, has adjusted corresponding customization method of servicing.
4. a kind of method based on Android platform JavaScript customization serviceization as described in claim 1, which is characterized in that The step 8) and step 9), implementation method getparms is: in the clothes that Android java class processing JavaScript tune rises The result of processing, is passed to JavaScript by loadUrl (jsCallback) method of Webview, adjusted by business The callback method of JavaScript.
5. it is a kind of based on Android platform JavaScript customization serviceization device, characterized by comprising:
Ginseng protocol element is passed, custom protocol is passed into ginseng to Webview for JavaScript;) initiate service request it is customized Agreement gives Android Webview;
First judging unit, for judging whether it is defined custom protocol;
Resolution unit obtains Transfer Parameters for parsing custom protocol;Protocol analysis transponder
Unit has been adjusted in reflection, has adjusted the corresponding customization service of custom protocol for reflecting;
Second judgment unit has adjusted customization to service successfully for judging whether;
Unit is adjusted back, ginseng readjustment processing parameter is passed to JavaScript as a result, tool by protocol analysis transponder for Webview Body realization is to inject js by webview method loadUrl (jsCallback) to adjust back to JavaScript;
End unit is used for end operation.
CN201910452883.2A 2019-05-28 2019-05-28 A kind of method and device based on Android platform JavaScript customization serviceization Pending CN110275730A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910452883.2A CN110275730A (en) 2019-05-28 2019-05-28 A kind of method and device based on Android platform JavaScript customization serviceization

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910452883.2A CN110275730A (en) 2019-05-28 2019-05-28 A kind of method and device based on Android platform JavaScript customization serviceization

Publications (1)

Publication Number Publication Date
CN110275730A true CN110275730A (en) 2019-09-24

Family

ID=67959151

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910452883.2A Pending CN110275730A (en) 2019-05-28 2019-05-28 A kind of method and device based on Android platform JavaScript customization serviceization

Country Status (1)

Country Link
CN (1) CN110275730A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113791752A (en) * 2021-09-16 2021-12-14 深圳市芯中芯科技有限公司 Method for synchronously controlling webpage music playing state through js in android system

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102207873A (en) * 2011-06-15 2011-10-05 中国联合网络通信集团有限公司 Realizing method of JavaScript extended object based on Android platform, and binding interface structure
CN105117222A (en) * 2015-08-19 2015-12-02 北京奇虎科技有限公司 Method and apparatus for providing android package (APK) customization service
CN109189469A (en) * 2018-06-22 2019-01-11 北京大学 Android application micro services method and system based on reflection

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102207873A (en) * 2011-06-15 2011-10-05 中国联合网络通信集团有限公司 Realizing method of JavaScript extended object based on Android platform, and binding interface structure
CN105117222A (en) * 2015-08-19 2015-12-02 北京奇虎科技有限公司 Method and apparatus for providing android package (APK) customization service
CN109189469A (en) * 2018-06-22 2019-01-11 北京大学 Android application micro services method and system based on reflection

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
HAPPYCODE002: "android webview与js简单的交互方案", 《博客园:HTTPS://WWW.CNBLOGS.COM/HAPPYXIAOYU02/P/9084387.HTML》 *
JENSEN95: "Android中Java和JS的交互", 《HTTPS://SEGMENTFAULT.COM/A/1190000011487440》 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113791752A (en) * 2021-09-16 2021-12-14 深圳市芯中芯科技有限公司 Method for synchronously controlling webpage music playing state through js in android system
CN113791752B (en) * 2021-09-16 2024-06-11 深圳市芯中芯科技有限公司 Method for synchronously controlling webpage music playing state in android system through js

Similar Documents

Publication Publication Date Title
CN110275831B (en) Mock data verification method and device of protocol interface
CN110377438B (en) Routing method, device and system of cross-process communication interface
CN106873961B (en) Method and device for awakening APP through mobile browser
US20180005631A1 (en) Performing tasks and returing audio and visual answers based on voice command
CA3152829A1 (en) Method and apparatus for processing business data
US20140376543A1 (en) System and method for providing a communication endpoint information service
CN109582395B (en) Applet running method and device, electronic equipment and storage medium
CN114553978B (en) Sensor message data processing method, electronic equipment and storage medium
CN104935744A (en) Verification code display method, verification code display device and mobile terminal
CN105635442A (en) Method and apparatus for displaying message on mobile terminal
CN110580154A (en) access method based on H5 access mode, access assembly and mobile terminal thereof
CN106897153B (en) Method and system for calling application programming interface
CN110058864A (en) The dispositions method and device of micro services
CN108984567A (en) A kind of Service Data Management system and method
WO2016082696A1 (en) Ua recognition method and device
US20110320286A1 (en) System And Method For Integrating An Ad Banner With A Calling Application
CN110390043A (en) Crawling method, device, terminal and the storage medium of webpage mailbox data
CN111159019A (en) Application program testing method, testing control terminal and testing terminal
CN108021445B (en) Memory optimization method, device and system and computer readable storage medium
CN110275730A (en) A kind of method and device based on Android platform JavaScript customization serviceization
CN114416075A (en) Service processing method and device
CN106681734A (en) Response method and device for function interface call
CN103812946B (en) Method and system for online cloud updating of AR application program
JP4800310B2 (en) Client provisioning with links
CN105068820B (en) A method of it is developed based on the integrated Axis of SSH frames and issues Web Service

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20190924

WD01 Invention patent application deemed withdrawn after publication