HTML5 App Simple Example

Source: Internet
Author: User

First, write a HTML5 App

Download the latest version of PhoneGap and unzip it and we will use the Android directory. : https://github.com/phonegap/phonegap/zipball/1.0.0

  • Start Eclipse, and then select New > Android Projectunder the menu "File".
    • Under the project root directory, create two new directories:
      • /libs
      • /assets/www
    • Copy Phonegap.js (from the PhoneGap unzipped Android directory, change the extracted JS file name to phonegap.js with the version number) to/assets/www.
    • Copy the Phonegap.jar (from the PhoneGap unzipped Android directory, change the extracted jar file name to Phonegap.jar) to/libs with the version number.
    • Copy the entire directory of XML (from PhoneGap's extracted Android directory, including a plugins.xml) to/res. "V1.0 RC2 above"
    • Make minor adjustments to the main Java files in the src folder of Eclipse: (e.g.)
      • Change the inheritance of class from Activity to droidgap
      • Replace Setcontentview () with super.loadurl ("file:///android_asset/www/index.html");
      • Add import com.phonegap.*;
      • Remove import android.app.Activity;
    • Here you may encounter an error that eclipse cannot find Phonegap.jar. In this case, right-click the/libs folder to find the build paths/> Configure build Paths. Then add Phonegap.jar to the project in the Libraries tab. If eclipse is not very stable, you need to click F5 to refresh the project once.
    • Open with > Text Editor .
    • after copying the following permission settings to Versionname (this can be determined by the app):
    <supports-screens android:anydensity= "true" android:largescreens= "true" android:normalscreens= "True" android:resizeable= "true" android:smallscreens= "true"/> <uses-permission android:name= "Android Oid.permission.CAMERA "/> <uses-permission android:name=" Android.permission.VIBRATE "/> <uses-permissio n android:name= "Android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name= " Android.permission.ACCESS_FINE_LOCATION "/> <uses-permission android:name=" android.permission.ACCESS_ Location_extra_commands "/> <uses-permission android:name=" Android.permission.READ_PHONE_STATE "/> <use S-permission android:name= "Android.permission.INTERNET"/> <uses-permission android:name= " Android.permission.RECEIVE_SMS "/> <uses-permission android:name=" Android.permission.RECORD_AUDIO "/> < Uses-permission android:name= "Android.permission.MODIFY_AUDIO_SETTINGS"/> &Lt;uses-permission android:name= "Android.permission.READ_CONTACTS"/> <uses-permission android:name= " Android.permission.WRITE_CONTACTS "/> <uses-permission android:name=" android.permission.WRITE_EXTERNAL_ STORAGE "/> <uses-permission android:name=" Android.permission.ACCESS_NETWORK_STATE "/>
added in the Activity tab of Androidmanifest android:configChanges="orientation|keyboardHidden" .
    • Create a new file "Index.html" in the "/assets/www" directory and paste the following code:
    • <! DOCTYPE html>
    • The last deployment runs the program.


second, the test

Mainactivity.java

Package Com.example.html5test;import Android.os.bundle;import Com.phonegap.droidgap;public class MainActivity Extends Droidgap {String url = "file:///android_assets/www/index.html";p ublic void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Super.loadurl (URL);}}

Test Results:

Modify Mainactivity.java

Package Com.example.html5test;import Android.app.activity;import Android.os.bundle;import Android.webkit.websettings;import Android.webkit.webview;public class Mainactivity extends Activity {WebView Mwebview ; String url = "file:///android_assets/www/index.html";p ublic void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (R.layout.fragment_main); WebView Mwebview = (WebView) This.findviewbyid (r.id.webid); Mwebview.loadurl (URL); WebSettings websettings = Mwebview.getsettings (); websettings.setjavascriptenabled (True);}}

Modify Fragment_main.xml

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:layout_width=" match_parent "    android:layout_height=" Match_parent "    android:paddingbottom= "@dimen/activity_vertical_margin"    android:paddingleft= "@dimen/activity_ Horizontal_margin "    android:paddingright=" @dimen/activity_horizontal_margin "    android:paddingtop=" @dimen /activity_vertical_margin "    tools:context=" com.example.html5test.mainactivity$placeholderfragment ">    <textview        android:layout_width= "wrap_content"        android:layout_height= "Wrap_content"        android: text= "@string/hello_world"/>    <webview        android:id= "@+id/webid" android:layout_width= "Wrap_        Content "        android:layout_height=" wrap_content "        android:layout_margintop=" 100DP "/></ Relativelayout>

Test results:

Third, reference reference

http://awebird.com/blog/art/122

http://awebird.com/blog/art/190

http://www.csdn.net/article/a/2015-04-21/15823933

http://blog.csdn.net/kuangshazi515/article/details/7725624

Http://www.cnblogs.com/charley_yang/archive/2011/02/28/1967559.html


The specific questions listed, have not been resolved, Daniel discussed together to help solve.

HTML5 App Simple Example

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.