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