Fill out the web form from the application and submit

I have a web page with a simple form with 3 input fields, name, email and course and submit button. Nothing unusual.

When developing an Android application, I would like to know how I could fill out this web form from my Android application without using a web view to actually load the web page.

+4
source share
5 answers

I have used something similar in the past. However, you will need to download the webview (although you do not need to show it). Then do something like below. Keep in mind that if the site changes the identifier along the way, this approach will not work.

webView.loadUrl("javascript:var 
    name=document.getElementById('nameInput').value='" yourNameValue "'");
webView.loadUrl("javascript:document.getElementById('submit').click()");
+1
source

build.gradle(Module: app)

dependencies {
implementation 'com.android.support:customtabs:27.0.2'
}

.

public boolean isPackageExisted(String targetPackage){
PackageManager pm=getPackageManager();
    try {
        PackageInfo info=pm.getPackageInfo(targetPackage,PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
    return true;
}

onCreate of Activity

if (isPackageExisted("com.android.chrome")){
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();                        
customTabsIntent.intent.setPackage("com.android.chrome");                             
customTabsIntent.intent.setAction(Intent.ACTION_VIEW);                             
customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);                          
customTabsIntent.launchUrl(getApplicationContext(), Uri.parse("Your URL"));
}
+1

webview. :

  • android
  • -

. submit tutorial

+1

Volley : https://developer.android.com/training/volley/index.html multipart-form-data;), "" , , , multipart-form-data, .

+1

Without a WebView, you cannot load a web page or create an html page in java. you can present the web page as the page of your application by hiding the URL address Disable the address bar in the Android web browser

or you want to read a string from a url, use this Get text from a web page to a string

0
source

Source: https://habr.com/ru/post/1689575/


All Articles