Convert Website Into An Android App | #2 Make your first simple webview app
1. เคจिเคे เคฆिเค เคนुเค Code เคो Activity_Main.xml เคฎें Image เคฎें เคฆिเคाเค เคนुเค เคธ्เคฅाเคจ เคชเคฐ paste เคเคฐे!
<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" />
2. เค เคฌ เคจिเคे เคฆिเค เคนुเค Code เคो MainActivity.java เคฎें Image เคฎें เคฆिเคाเค เค เคจुเคธाเคฐ Package Name เคो เคोเฅเคเคฐ เคฌाเคी Code เคे เคธ्เคฅाเคจ เคชเคฐ Paste เคเคฐें!
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
String websiteURL = "https://YouTube.com/technicalsangrah"; // sets web url
private WebView webview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//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());
}
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;
}
}
}
# เค เคญी เคเคชเคे app เคो internet use เคा permission เคจเคนीं เคฎिเคฒा เคนै
4. Internat permission เคे เคฒिเค เคจिเคे เคฆिเค เคนुเค code เคो AndroidManifest.xml (Go to app > manifests > AndroidManifest.xml ) เคฎें image เคฎें เคฆिเคाเค เค เคจुเคธाเคฐ Paste เคเคฐें!
<uses-permission android:name="android.permission.INTERNET" />
# เค เคฌ เคฎेเคฐा Code เคเคธ เคคเคฐเคน (เคจिเคे เคฆिเคाเคฏा เคเคฏा เคนै) เคฆिเคाเค เคฆे เคฐเคนा เคนै!
# เค เคฌ เคเคช เค เคชเคจे app เคो Mobile เคธे Connect เคเคฐเคे เคฆेเค เคธเคเคคे เคนैं!
Comments
Post a Comment