0% found this document useful (0 votes)
86 views

Convert Web to App With Android Studio Ladybug

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views

Convert Web to App With Android Studio Ladybug

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Convert Web to App With

Android Studio Ladybug


JAVA | KOTLIN 2024
Author: MUHAMMAD HASBI POHAN | 2024

1. Make New Project on Android Studio Ladybug.


2. Choose Empty Views Activity
3. Set Your App Name and set Language to Java
4. Set Minimum SDK and Set Build Configuration Language to Kotlin DLS
5. Go to activity_main.xml and changes from:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

To

<WebView
android:id="@+id/webview"
android:layout_height="match_parent"
android:layout_width="match_parent"/>

6. Go to MainActivity.java and changes from:


import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);

ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v,
insets) -> {
Insets systemBars =
insets.getInsets(WindowInsetsCompat.Type.systemBars());

Halaman | 1
v.setPadding(systemBars.left, systemBars.top,
systemBars.right, systemBars.bottom);
return insets;
});
}
}

To

import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

WebView mWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);

ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v,
insets) -> {
Insets systemBars =
insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top,
systemBars.right, systemBars.bottom);
return insets;
});
mWebView = findViewById(R.id.webview);
mWebView.setWebViewClient(new myWebViewclient()); // to handle
URL redirects in the app
mWebView.getSettings().setJavaScriptEnabled(true); // to enable
JavaScript on web pages
mWebView.getSettings().setGeolocationEnabled(true); // to enable
GPS location on web pages
mWebView.loadUrl("https://www.GOOGLE.com");
}

public class myWebViewclient extends WebViewClient {

@Override
public boolean shouldOverrideUrlLoading(WebView view, String
url) {

view.loadUrl(url);

return true;
}

Halaman | 2
@Override
public void onPageStarted(WebView view, String url, Bitmap
favicon) {
super.onPageStarted(view, url, favicon);

final String urls = url;


if (urls.contains("mailto") || urls.contains("whatsapp") ||
urls.contains("tel") || urls.contains("sms") ||
urls.contains("facebook") || urls.contains("truecaller") ||
urls.contains("twiter")) {
mWebView.stopLoading();
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse(urls));
startActivity(i);

@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);

}
}

@Override
public void onBackPressed() {
if (mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
}

}
Note: Don’t change the first line (the application package) and the link.

7. Go to AndroidManifest.xml and on line 4 add:


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

8. And You Can Costumize Your App Logo, Permission and etc on
AndroidManifest.xml
9. And You Can Run With Emulator on Android Studio or Build Your App to
APK on Build Menu
10. Finish.

Halaman | 3
Referance
TheTecnic. (2024, May 30). How to create WebView in Android Studio. TheTecnic. Retrieved from
https://web.archive.org/web/20240530093112/https://thetecnic.com/mobile-apps/android/how-to-create-
webview-in-android-studio/

Code With Cal. (2023, November 11). How to create WebView in Android Studio [Video]. YouTube.
https://youtu.be/-yaMic99LdY?si=ZDoHUb-kvd7HNhTO

Halaman | 4

You might also like