Skip to content
Build mobile aplications with html, css and javascript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
www
.gitignore
README.md

README.md

iPhone

  • Create a new View-based Application on Xcode
  • In ViewController.m just insert this follow code:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
        webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        webView.scrollView.bounces = NO;
        webView.delegate = self;
    
        NSString *indexPath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"www"];
        NSURL *url = [NSURL fileURLWithPath:indexPath];
        NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
        [webView loadRequest:requestObj];
    
        [self.view addSubview:webView];
    
        [webView stringByEvaluatingJavaScriptFromString:@""
         "window.alert = function (message, title) {"
         "  title = title || 'Alert';"
         "  location.href = 'alert:' + title + ':' + encodeURI(message);"
         "};"];
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return YES;
    }
    
    - (void)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request 
     navigationType:(UIWebViewNavigationType)navigationType {
        NSURL *url = [request URL];
        NSString *method = [url scheme];
    
        if ([method isEqual:@"alert"]) {
            NSArray *components = [[url absoluteString] componentsSeparatedByString:@":"];
    
            NSString *title = [[components objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            NSString *message = [[components objectAtIndex:2] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok",nil];
    
            [alert show];
        }
    }
    
  • If want to set a javascript function from Objective-C code, do this inside 'viewDidLoad':

    [webView stringByEvaluatingJavaScriptFromString:@"Your JavaScript code here"];
    
  • Right-click in project at left-side column and select "Show in finder"
  • Create a 'www' folder in project directory, drag this folder to Xcode and drop at left-side column project root
  • Choose the radio 'Create folder references for any added folders' and click 'Finish'
  • Build your web application on www folder (index.html needs to be start-page)
  • Test your application.

Android

  • In terminal, type:

    android create project
    
  • Follow terminal instructions to create your android project
  • Edit AndroidManifest.xml file to this: (Change [PACKAGE NAME] to "com.organization.project" and [ACTIVITY NAME] to "Project")

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="[PACKAGE NAME]"
          android:versionCode="1"
          android:versionName="1.0">
        <application android:label="@string/app_name"
                     android:icon="@drawable/icon">
            <activity android:name="[ACTIVITY NAME]"
                      android:label="@string/app_name"
                      android:theme="@android:style/Theme.NoTitleBar"
                      android:configChanges="orientation|keyboardHidden">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
        <supports-screens android:smallScreens="true"
                          android:normalScreens="true"
                          android:largeScreens="true"
                          android:xlargeScreens="true"
                          android:anyDensity="true" />
        <uses-sdk android:minSdkVersion="2" />
        <uses-permission android:name="android.permission.INTERNET" />
    </manifest>
    
  • Edit res/layout/main.xml file to this:

    <?xml version="1.0" encoding="utf-8"?>
    <WebView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />
    
  • Edit src/[PACKAGE PATH]/[APPLICATION NAME].java file to this: (Change [PACKAGE NAME] to "com.organization.project" and [ACTIVITY NAME] to "Project")

    package [PACKAGE NAME];
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    
    public class [ACTIVITY NAME] extends Activity
    {
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            WebView myWebView = (WebView) findViewById(R.id.webview);
            myWebView.setWebViewClient(new WebViewClient());
            //myWebView.setVerticalScrollBarEnabled(false);
            myWebView.setHorizontalScrollBarEnabled(false);
            myWebView.getSettings().setJavaScriptEnabled(true);
            myWebView.getSettings().setDomStorageEnabled(true);
            myWebView.getSettings().setDatabasePath("/data/data/" + getPackageName() + "/databases");
            myWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
            myWebView.loadUrl("file:///android_asset/www/index.html");
        }
    }
    
  • Create res/drawable folder and insert a 72x72px icon.png file
  • Create assets/www folder and build your web application in this folder (index.html needs to be start-page)
  • Test your application.

    ant debug install
    
Something went wrong with that request. Please try again.