2
The thing is, I’m making an app that’s kind of webbrowser. In this app, I have a url written inside a . txt, and I need to load this URL into my Webview. Follow what I’ve already done:
NOTE: I can already load a URL in my Webview by specifying it in the apk code itself as you can see in the codes below.
activity_main.xml:
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
<Button
    style="?android:attr/buttonStyleSmall"
    android:layout_width="50px"
    android:layout_height="50px"
    android:id="@+id/button"
    android:background="@drawable/engrenagem"
    android:layout_alignWithParentIfMissing="false"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_margin="20px" />
Mainactivity.java:
package com.abacoti.awser;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;  ;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
    String webURL = "http://www.google.com/";
    WebView web;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
        web = (WebView) findViewById(R.id.webview);
        if (savedInstanceState == null)
        {
            web.loadUrl(webURL);
        }
        WebSettings webSettings = web.getSettings();
        webSettings.setJavaScriptEnabled(true);
        web.setWebViewClient(new WebViewClient());
    }
    @Override
    protected void onSaveInstanceState(Bundle outState )
    {
        super.onSaveInstanceState(outState);
        web.saveState(outState);
    }
    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState)
    {
        super.onRestoreInstanceState(savedInstanceState);
        web.restoreState(savedInstanceState);
    }
    @Override
    public void onBackPressed() {
    }
}
						
It’s not very clear what you want to do. You can better illustrate?
– Pablo Almeida
You want to load a page from a specified URL into a text file or you want to render what is in the text file inside the
WebView?– Roney Gomes
The URL (LINK) is written inside the TXT file?
– denis
Exactly! I’ll edit the question!
– Marcos Sartorato
I will re-open the question, but next avoid changing both the question with edits, especially when there are already answers. See you soon!
– Sergio
Thank you! Anyway, William had already responded and edited his reply.
– Marcos Sartorato