【问题标题】:Convert my localhost website into android app将我的 localhost 网站转换为 android 应用程序
【发布时间】:2019-05-17 23:06:38
【问题描述】:

我想创建一个 localhost 网站或非在线网站的 web 视图,我该怎么做它选择在线网站链接而不是 localhost 有没有办法做到这一点?

我尝试使用 localhost 和 ip 提供链接,但它没有选择我的网站。

MainActivity.java


import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {
 private WebView mywebview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mywebview = findViewById(R.id.webview);
        WebSettings webSettings = mywebview.getSettings();
        webSettings.getJavaScriptEnabled();
        mywebview.loadUrl("http://192.000.00.0/traveland/index.php");
        mywebview.setWebViewClient(new WebViewClient());
    }

    @Override
    public void onBackPressed()
    {
        if(mywebview.canGoBack())
        {
            mywebview.goBack();
        }
        else
        {
            super.onBackPressed();
        }

    }
}

MainActivity.xml

<RelativeLayout 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:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp"
        android:id="@+id/webview"/>
</RelativeLayout>```

It shows all the online websites not the offline ones how can that be done?

【问题讨论】:

  • 如果是本地网站,为什么不将其存储在本地,然后存储在 Android 设备上?而不是那个 IP,因为如果在 Google 上发布它,没有人将能够访问,因为他们不在网络中

标签: android localhost android-webview


【解决方案1】:

你的电脑和安卓必须在同一个网络中,一旦你打开你的网络服务器(WAMP、XAMPP 等),配置 vitualhots,并从你的电脑禁用防火墙。

【讨论】:

  • 您能详细说明一下 vitualhots 吗?如何做到这一点
【解决方案2】:

如果您的 localhost 运行良好,并且您想让它成为一个通过您的 android 与服务器 localhost 连接的应用程序,那么请在您的 PC 上下载“ngrok”。有大量教程将教您如何在线托管本地主机网站,一旦您这样做,您将粘贴该 ngrok URL,它是您网站的在线版本,然后命名您的应用程序给您的电子邮件,然后像普通表单一样提交您将收到电子邮件,并且会有两个链接。一个用于您的应用程序的公共链接共享,另一个是私有应用程序管理,它允许您更改应用程序的某些功能,例如 URL 和其他人只需将 URL 更改为您的 localhost URL,然后您将能够访问本地网站的内容而无需 ngrok 请记住,如果您更改 Web 应用程序的布局,那么您必须再次通过相同的过程更新您的应用程序 本站制作app链接:https://gonative.io/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-08
    • 2012-12-08
    • 2015-02-26
    • 2021-08-31
    • 2017-03-05
    • 1970-01-01
    • 2015-10-26
    • 2014-04-25
    相关资源
    最近更新 更多