Convert your website to a android apk with Android Studio
Convert any website to an android apk using android studio using the following steps :
1. Open your android studio.
2. Click on create new project.
4. Open your AndroidMainfest.xml file in apps->mainfests folder.
5. Paste the following lines of code there and save it.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mtcst">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/Theme.MTCST">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
6. Now open your MainActivity.java file, paste the following code and save it.
package com.example.mtcst;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
private WebView mywebview;
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mywebview=(WebView) findViewById(R.id.webview);
WebSettings webSettings=mywebview.getSettings();
webSettings.setJavaScriptEnabled(true);
mywebview.loadUrl("http://mtcst.rf.gd");
mywebview.setWebViewClient(new WebViewClient());
}
@Override
public void onBackPressed()
{
if(mywebview.canGoBack())
{
mywebview.goBack();
}
else
{
super.onBackPressed();
}
}
}
7. Change the parameter in loadUrl function to your website name.
8. Now open your activity_main.xml file, paste the following code and save it.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteY="1dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
9. Navigate to build option and build your project.
10. You can also run your project with the run option so you can view your apk in your pc.
11. Navigate to your project file
C:\Users->(user_name)->AndroidStudioProjects->(project_name)->app->build->outputs->apk->debug->app-debug.apk
The above location is the default location of your project and app-debug.apk is the apk that you created.
Comments
Post a Comment