Android SDK-应用程序不';不读php/MySQL

Android SDK-应用程序不';不读php/MySQL,php,android,mysql,sdk,Php,Android,Mysql,Sdk,正如我在标题中所说的 Activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:c

正如我在标题中所说的

Activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    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"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

</RelativeLayout>
以及News.php文件

<html>
<head>
<link rel="stylesheet" type="text/css" href="file:///android_asset/style.css" media="screen"/>
</head>
<body>
<img alt="full screen background image" src="file:///android_asset/back.jpg" id="full-screen-background-image" />
<center><img alt="up" src="file:///android_asset/top.png" id="up" /> </center>
<center><img alt="down" src="file:///android_asset/down.png" id="down"/></center>
<h2><center>
Les nouvelles (Blagues)
</center></h2>
<ul>
<a href="file:///android_asset/index.html"><li class="arrow">La page precedente</li></a>
</ul>
<ul>
<?php
$con = mysql_connect("The Domain","Username","Password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("DB Name", $con);

$result = mysql_query("SELECT * FROM espace");

while($row = mysql_fetch_array($result))
  {
echo "<a href=".$row['link'].">","<li class=".$row['arrow'].">";
echo $row['news'];
echo "</li></a>";
  };
mysql_close($con);
?>
</ul>
</body>
</html>
需要许可吗


感谢您的帮助

Android无法在设备上运行PHP代码。PHP是一种服务器端语言,您必须将所有PHP功能移动到Web服务器上,并通过该服务器访问它


请注意,您可以使用一个项目在本地运行代码,但我不确定端口的完整性或活动性。

php页面是一个脚本,需要一个php解释器来解析和正确显示。你不能在你的安卓系统中使用它(这不是你真正想要的)。您需要将此脚本存储在与PHP兼容的web服务器中,并通过手机浏览器通过internet查看它(同样,我想这不是您想要的)

获取Android的web服务器,将您的PHP脚本移动到
htdocs
(或其他)当作为
localhost:8080/
调用时,文档文件夹和所有内容都将正常运行。我在智能手机和平板电脑上都使用KSWeb服务器,没有任何问题。

你真的想在Android设备上解释
.php
文件吗?所以我应该制作一个iframe?@AlexandreAchkar不完全是我的意思,但只要php代码在支持php的Web服务器上,并且你正在将其加载到iframe中,就可以了。
package com.achkars.espaceado;

import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebChromeClient;
import android.webkit.WebView;

public class MainActivity extends Activity {

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        WebView webview = new WebView(this);
         setContentView(webview);
         webview.getSettings().setJavaScriptEnabled(true);
         webview.setWebChromeClient(new WebChromeClient());
        // Simplest usage: note that an exception will NOT be thrown
         // if there is an error loading this page (see below).
         webview.loadUrl("file:///android_asset/index.html");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}
<html>
<head>
<link rel="stylesheet" type="text/css" href="file:///android_asset/style.css" media="screen"/>
</head>
<body>
<img alt="full screen background image" src="file:///android_asset/back.jpg" id="full-screen-background-image" />
<center><img alt="up" src="file:///android_asset/top.png" id="up" /> </center>
<center><img alt="down" src="file:///android_asset/down.png" id="down"/></center>
<h2><center>
Les nouvelles (Blagues)
</center></h2>
<ul>
<a href="file:///android_asset/index.html"><li class="arrow">La page precedente</li></a>
</ul>
<ul>
<?php
$con = mysql_connect("The Domain","Username","Password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("DB Name", $con);

$result = mysql_query("SELECT * FROM espace");

while($row = mysql_fetch_array($result))
  {
echo "<a href=".$row['link'].">","<li class=".$row['arrow'].">";
echo $row['news'];
echo "</li></a>";
  };
mysql_close($con);
?>
</ul>
</body>
</html>
"," ";echo $row['news'}; echo " 
";}; mysql_close($con); ?>