Preface
I believe you have heard about the well-known phonegap. I will not detail its strength. You can search for it online. Here, I would like to emphasize that phonegap provides Android, iPhone, palm, and wrapper for the BlackBerry platform, so that mobile Web pages can be packaged as native software, you do not need to use a browser as the portal.
This article will discuss how to use phonegap and third-party plug-ins of phonegap from the application perspective.
I will introduce the third-party plug-in childbrowser of phonegap.
Project Practice
Project preparation:
0. Android Development Environment (eclipse + ADT + androidsdk + ...)
1. Download the package required by phonegap (cordova-2.1.0.jar, cordova-2.1.0.js, XML/config. XML)
2. download the file (childbrow.js, childbrow.java,...) required by the third-party plug-in childbrow.phonegap ,...)
Project Description:
In this project, I first created an android project-Android-phonegap, integrated the phonegap, then integrated the childbrowser into the project, and finally customized an appshell plug-in.
Create an Android-phonegap Project
I will not introduce this chapter in detail. You can refer to the official tutorial.
The created structure is as follows:
App. Java 1 public class app extends droidgap {
2
3 @ override
4 Public void oncreate (bundle savedinstancestate ){
5 super. oncreate (savedinstancestate );
6 setcontentview (R. layout. app_layout );
7 super. loadurl ("file: // android_asset/www/test.html ");
8}
9
10}
The following points must be emphasized:
1. The app must inherit droidgap, super. loadurl ("file: // android_asset/www/test.html"); you can also load HTTP resources
2. Copy cordova-2.1.0.js to assets/WWW folder
3. Copy cordova-2.1.0.jar to libs folder
4. Copy XML/config. XML to the res folder.
Integrate the third-party plug-in childbrowser of phonegap to the Project
1. create the package COM. cc. mobile. phonegap. plugins, And the childbrowser in the \ childbrowser \ 2.0.0 \ SRC \ com \ phonegap \ plugins \ childbrowser folder. copy Java to it
2. create the plugins folder under the assets of the Android-phonegap project. copy the JS file to it and copy the three images in the childbrowser directory.
3. Add the following information to the XML \ config. xml file:
<Plugin name = "childbrowser" value = "com. CC. Mobile. phonegap. plugins. childbrowser"> </plugin>
After integration
The integrated Res/XML/config. xml file config. xml 1 <? XML version = "1.0" encoding = "UTF-8"?>
2 <! --
3 licensed to the Apache Software Foundation (ASF) under one
4 or more contributor license agreements. See the notice file
5 distributed with this work for additional information
6 regarding copyright ownership. The ASF licenses this file
7 to you under the Apache license, version 2.0 (
8 "License"); you may not use this file except T in compliance
9 with the license. You may obtain a copy of the license
10
Http://www.apache.org/licenses/LICENSE-2.0 11
12
13 unless required by applicable law or agreed to in writing,
14 software distributed under the license is distributed on
15 "as is" basis, without warranties or conditions of any
16 kind, either express or implied. See the license for
17 specific language governing permissions and limitations
18 under the license.
19 -->
20 <Cordova>
21 <! --
22 access elements control the android whitelist.
23 domains are assumed blocked unless set otherwise
24 -->
25
26 <access origin = "http: // 127.0.0.1 *"/> <! -- Allow local pages -->
27
28 <! -- <Access origin = "https://example.com"/> allow any secure requests to example.com -->
29 <! -- <Access origin = "https://example.com" subdomains = "true"/> such as abve, but including subdomains, such as WWW -->
30 <access origin = ". *"/>
31
32 <Log Level = "debug"/>
33 <preference name = "usebrowserhistory" value = "false"/>
34 <preference name = "Exit-on-Suspend" value = "false"/>
35 <plugins>
36 <plugin name = "app" value = "org. Apache. Cordova. app"/>
37 <plugin name = "geolocation" value = "org. Apache. Cordova. geobroker"/>
38 <plugin name = "device" value = "org. Apache. Cordova. Device"/>
39 <plugin name = "accelerometer" value = "org. Apache. Cordova. accellistener"/>
40 <plugin name = "Compass" value = "org. Apache. Cordova. compasslistener"/>
41 <plugin name = "Media" value = "org. Apache. Cordova. audiohandler"/>
42 <plugin name = "camera" value = "org. Apache. Cordova. cameralauncher"/>
43 <plugin name = "contacts" value = "org. Apache. Cordova. contactmanager"/>
44 <plugin name = "file" value = "org. Apache. Cordova. fileutils"/>
45 <plugin name = "networkstatus" value = "org. Apache. Cordova. NetworkManager"/>
46 <plugin name = "notification" value = "org. Apache. Cordova. Notification"/>
47 <plugin name = "Storage" value = "org. Apache. Cordova. Storage"/>
48 <plugin name = "temperature" value = "org. Apache. Cordova. templistener"/>
49 <plugin name = "filetransfer" value = "org. Apache. Cordova. filetransfer"/>
50 <plugin name = "capture" value = "org. Apache. Cordova. Capture"/>
51 <plugin name = "battery" value = "org. Apache. Cordova. batterylistener"/>
52 <plugin name = "splashscreen" value = "org. Apache. Cordova. splashscreen"/>
53 <plugin name = "Echo" value = "org. Apache. Cordova. Echo"/>
54
55 <! -- Start customized plugins -->
56 <plugin name = "childbrowser" value = "com. CC. Mobile. phonegap. plugins. childbrowser"> </plugin>
57 </plugins>
58 </Cordova>
The integration is completed.
Follow-up
The following sections detail how to use phonegap for actual development, how to use the childbrowser plug-in, and how to customize your own third-party plug-ins.
Reference
Http://docs.phonegap.com/en/2.1.0/guide_getting-started_android_index.md.html#Getting%20Started%20with%20Android
Https://github.com/phonegap/phonegap-plugins/tree/master/Android/ChildBrowser
Http://www.inside.com.tw/2010/08/15/phonegap-eliminates-the-gap-between-mobile-web-and-native-app
Http://www.inside.com.tw/2011/01/29/hello-inside-phonegap
Author information:
QQ: 1321518080
Email: hucaijun520. OK @163.com