Androidstudio pack HTML5 into an APK

Source: Internet
Author: User

I want to pack the animated effect of HTML5 into a mobile app to make it easy to spread. And in the Android development of the components directly from the WebView can access the Web page, in addition to Android project, the contents of the Assets folder is not compiled, so you can put the well-done HTML5 project under the folder, Open the index.html under this folder by the WebView control, so you can implement HTML5 package cheer apk.

1, modify the Mainactivity.java, the content is as follows:

 PackageCom.example.admin.yourProjectName;//Change to your project name Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.os.Bundle;Importandroid.app.Activity;Importandroid.view.KeyEvent;ImportAndroid.webkit.WebView; Public classMainactivityextendsappcompatactivity {PrivateWebView WebView; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); //instantiating a WebView objectWebView =NewWebView ( This); //set the WebView property to be able to execute JavaScript scriptsWebview.getsettings (). setjavascriptenabled (true); //load Web pages that need to be displayed//webview.loadurl ("File:///android_asset/index.html ");//Show Local pageWebview.loadurl ("https://www.baidu.com");//Show Remote Web page//set up a Web viewSetcontentview (WebView); } @Override//Set Fallback     Public BooleanOnKeyDown (intKeyCode, KeyEvent event) {        if((keycode = = Keyevent.keycode_back) &&Webview.cangoback ()) {Webview.goback ();//GoBack () indicates that the previous page of the WebView is returned            return true; }        return false; }} Note: If a local page is displayed, you need to right-click on the App folder in Project View-New->folder->Assets folder. The individual files of the local page are then copied to the generated Assets folder, and the Webview.loadurl ("The file:///android_asset/...") to the corresponding local URL. 

2. Modify the ability to add access to the network in the Androidmanifest.xml file: add it before the label

<uses-permission android:name= "Android.permission.INTERNET"/>

Can.

package = "Com.example.admin.yourProject" >     <application android:allowbackup= "true" Android:icon = "@mipmap/ic_launcher" android:label= "@string/app_name" android:supportsrtl= "true" Android:theme= "@style/apptheme ">        <activity android:name=". Mainactivity ">            <intent-filter>                <action android:name=" Android.intent.action.MAIN "/>                 <category android:name= "Android.intent.category.LAUNCHER"/>            </intent-filter>        </activity >    </application>    <uses-permission android:name= "Android.permission.INTERNET"/></ Manifest>

Androidstudio pack HTML5 into an APK

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.