New things 002--android Use PhoneGap

Source: Internet
Author: User

Recent project progress is not very tense, the manager told us to see if you can use PhoneGap in the project, he wants to introduce phonegap to solve the problem of screen adaptation and reduce the difficulty of android,ios development. So, it took a week to get a glimpse of PhoneGap, But we're not sure how it's going to work.

I. Introduction of PHONEGAP

I use the older phonegap-2.9.0 (because this online information more, and its demo content is more rich, the current latest demo feeling than poor, after reading even he can realize what do not know, so I gave up the use of the latest, But the newest should be updated something better than before, just now, who care),

1.1 Download phonegap2.9.0 from PhoneGap, and place Cordova-2.9.0.jar in the Lib/android/directory under the downloaded directory in your project LIB, as the jar package that you want to use as a later project

1.2 Create a WWW folder under your project's assets directory, and place the/lib/android/example/assets/www/cordova.js under your downloaded phonegap file under the WWW directory. This JS file is provided to you HTML to use the JS

1.3 Copy Cordova.js under the index.html, put in your project, you can also rewrite an HTML, this is your project to open the HTML, note, be sure to add JS support to him, so that you can invoke the function of the device, Otherwise, it's no different from a simple web HTML.

1.4 Copy the XML folder of the Exmple/res path under your download path, and copy it to the Res directory of your project (there are some parameters supported by the framework)

1.5 Add this permission to your project (you can find its mainfest from the example in the download file, as it affirms the right to rotate the screen and some operating devices)


Two. Using PhoneGap

Follow the steps above to get here, and you'll have a PHONEGAP framework for your project, followed by the use of

2.1 Overriding activity

Create your activity, let your activity not inherit activity, but inherit Droidgap (Eclipse may not automatically remind this class, you write first, then the leader can)

2.1 Rewrite the OnCreate method, note that this method has been changed to public, if you do not change, there will be a problem

2.2 Load the local HTML file in call Super.loadurl, but be sure to call Super.oncreate (Saveinstancestate) before you will get an error

2.3 The best way to remove the app.activity package

2.2 Write HTML

Write HTML, in the asserts directory under the WWW folder to write HTML, that is, with your JS in the same path, you can also download HTML files from the network, if you want to use the PHONEGAP framework, you have to put in this path, if you are the first time, Can directly modify the newly downloaded example/asserts/www under the index.html, or according to the official website (http://docs.phonegap.com/en/1.5.0/index.html) to write HTML, you can realize the function, in fact , a lot of HTML code on the official website has, copy down to run to see the effect on the line, but must ensure that you can run out


Three. Summary

On the official website, followed it to write all the HTML, in addition to some of the details of the problem, the rest is not much of a problem, but after writing, think of a likely silly question, is:

"Does Android use the PHONEGAP framework, and does the HTML used by the framework have to be local?" If you open Web HTML directly, can you control your local device? "

I think carefully, think not, because JS in the local, and not the server, the server's HTML can not call the local JS, so no, but PhoneGap can open the remote server HTML is completely no problem, just can't control the device in turn, this concept must be clear, later, This view has also been confirmed by the phonegap100. But specifically, I haven't tried.

New things 002--android Use PhoneGap

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.