How do we make a website in the app?
To make a site in an application, you should fabricate a portable application that can show web content. Here are the means you can follow to make a site in an application:
1. Pick a versatile application improvement stage: There are a few application advancement stages accessible, including local stages like iOS and Android, cross-stage systems like Respond Local and Ripple, and online stages like Phone Gap and Ionic.
2. Plan the UI: Whenever you have chosen a stage, you can plan the UI of your application. This will include making screens and designs that show web content, for example, site pages or implanted web sees.
3. Pick a web facilitating administration: You will require a web facilitating administration to have your site's substance. You can utilize a web facilitating administration like Blue host, Host Gator, or Go Daddy to have your site.
4.Fabricate your site: You can construct your site utilizing web advancement devices like HTML, CSS, and JavaScript. You can utilize a Substance The board Framework (CM) like WordPress to make and deal with your site's substance.
5.Coordinate your site with your application: You should incorporate your site with your application so that the application can show the web content. This should be possible by utilizing a Web View or comparable part to show the web content inside the application.
6.Test and convey your application: Whenever you have fabricated your application, you should test it to ensure it works accurately. You can then convey your application to the application stores with the goal that clients can download and utilize it.
By and large, making a site in an application includes building a portable application that can show web content and coordinating your site with your application utilizing a Web View or comparative part.
Follow Step by Step
Step 1 - First of all open android studio then click on new project then select on phone and tablet and click on empty activity and click on next. After that you type the name of the app, then select Java on the language, then click on the finish option.
Step 2 - Have to start working when the message show of build successful in android studio.
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Step 4 - Now copy the code given below and paste it in the Activity_Main .XML in the layout in the app (remove the text view and paste it here).
Also Read - How To Create Splash Screen Android Studio
android:id="@+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/webView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
tools:ignore="MissingConstraints" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
Step 5- Now you have to copy the code given below and paste it ( Copy and paste the import from here ) in MainActivity.Java in the app. If there is an error in the code, then by right-clicking on the error text, click on the option (Add permission access network state / Import class), then all the errors will be fixed.
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.appcompat.app.AppCompatActivity;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
public class MainActivity extends AppCompatActivity {
String websiteURL = " Your Website "; // sets web url
private WebView webview;
SwipeRefreshLayout mySwipeRefreshLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if( ! CheckNetwork.isInternetAvailable(this)) //returns true if internet available
{
//if there is no internet do this
setContentView(R.layout.activity_main);
//Toast.makeText(this,"No Internet Connection, Chris",Toast.LENGTH_LONG).show();
new AlertDialog.Builder(this) //alert the person knowing they are about to close
.setTitle("No internet connection available")
.setMessage("Please Check you're Mobile data or Wifi network.")
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
//.setNegativeButton("No", null)
.show();
}
else
{
//Webview stuff
webview = findViewById(R.id.webView);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setDomStorageEnabled(true);
webview.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
webview.loadUrl(websiteURL);
webview.setWebViewClient(new WebViewClientDemo());
}
//Swipe to refresh functionality
mySwipeRefreshLayout = (SwipeRefreshLayout)this.findViewById(R.id.swipeContainer);
mySwipeRefreshLayout.setOnRefreshListener(
new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
webview.reload();
}
}
);
}
private class WebViewClientDemo extends WebViewClient {
@Override
//Keep webview in app when clicking links
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
mySwipeRefreshLayout.setRefreshing(false);
}
}
//set back button functionality
@Override
public void onBackPressed() { //if user presses the back button do this
if (webview.isFocused() && webview.canGoBack()) { //check if in webview and the user can go back
webview.goBack(); //go back in webview
} else { //do this if the webview cannot go back any further
new AlertDialog.Builder(this) //alert the person knowing they are about to close
.setTitle("EXIT")
.setMessage("Are you sure. ?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.setNegativeButton("No", null)
.show();
}
}
}
class CheckNetwork {
private static final String TAG = CheckNetwork.class.getSimpleName();
public static boolean isInternetAvailable(Context context)
{
NetworkInfo info = (NetworkInfo) ((ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
if (info == null)
{
Log.d(TAG,"no internet connection");
return false;
}
else
{
if(info.isConnected())
{
Log.d(TAG," internet connection available...");
return true;
}
else
{
Log.d(TAG," internet connection");
return true;
}
}
}
}
Change app Icon - In android studio below java res option will show right click on it and click on new then click on image asset then you will see path option then select image from it then resize size and click on finish option then give reason your app icon will change
Step 6 - If you want to remove the option bar from your app, then simply go to the theme (if there are two options in the theme, then edit both) in the values in the app and make DarkActionBar To NoActionBar.
How to Convert Any Website to Android App in Android Studio Watch Now Video
Note - If you are facing any issue or any problem in android-studio, you will see a red line in that Text section, from that side line, you have to right click Then Show Context Action Create id value resource / Import class / Add permission access network state / click on it, then it will be fixed.
Conclusion - Congratulations, now your app is built, now you can test your Android app on Android Virtual Device.You can create multiple apps in this way and you can also add Splash Screen to the app.