Vincent Valentine Vincent Valentine - 1 month ago 8
Android Question

Using nodejs as a server on android device?

I'm making an application that using nodejs as a server on android device. Server will handle req and return html interface to desktop client via their web browser but i don't know what to start with Android studio.

Answer

I am guessing, that you want to use load html returned by server in the Android app. if that is the case, you can simply create an activity with a webview and load the same url you would load in the app.

You can follow this documentation https://developer.android.com/guide/webapps/webview.html to load url.

simply put, have a layout with webview

<?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"/>

and in the activity load your servers url.

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://www.example.com");

and if you want handle all links in that html to be opened in the same app follows this Clicking URLs opens default browser

But this is as good as somone opening the url in a browser in android phone, to give a better experience, you server should be able to give data as JSON or XML or any other data format and you should be able to build a native app on that data.

If this is not what you were looking for, apologies.

Comments