How To Make Android App From Website - Compressed
How To Make Android App From Website - Compressed
if not first time use Android Studio, Android Studio will auto open last project,now you can click File-
->New-->New Project....
Select “Empty Activity”,click “Next”.
Input text for “Name, Package name, Save location” ,others as default, not need to change, click
“Finish”.
Name: Project name.
Package name: The unique ID of the project cannot be the same as other applications,
otherwise the installation will fail. It's better to start with your own domain name, such
as com.kincony
<WebView
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Use WebView load webpage
Open “MainActivity”, define website url you want to open, such as:
private String url = " http://iot.kincony.com:1880/ui/#!/0?socketid=yJktDF85HVA4B5J1AACe";
This is your url.
Config WebView as red region:
Code list:
import android.os.Build;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
webView = findViewById(R.id.web_view);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setAllowFileAccess(true);
webSettings.setAllowContentAccess(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setBlockNetworkImage(false);
webSettings.setTextZoom(100);
webSettings.setSupportZoom(true);
webSettings.setBuiltInZoomControls(false);
webSettings.setDisplayZoomControls(false);
webSettings.setDefaultTextEncodingName("UTF-8");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
webSettings.setAllowFileAccessFromFileURLs(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
webSettings.setDomStorageEnabled(true);
webSettings.setAppCacheEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
webView.loadUrl(url);
Config completed.
@Override
public void onBackPressed() {
if (webView.canGoBack()) {
webView.goBack();
} else {
super.onBackPressed();
}
}
Debug
Click Build-->Build Bunle(s)/APK(s)-->Build APK(s) Compile the project into an APK file
Waitting Android Studio Compile, it will takes about 1 minute.
After compiling, a prompt will pop up. Click the “locate” button on the prompt to directly open the APK file
directory
If there is no pop-up prompt, you can also search under the save location path defined before.
“Save location” path: app/build/outputs/apk/debug
Modify application name
If you not make all types of ico, you only need make ico for “mipmap-xxhdpi” or “mipmap-xxxhdpi” folder
is ok.
After change the ico file, click “Build-->Build Bunle(s)/APK(s)-->Build APK(s)” recompile the project to
APK file.