doujiu6976 2014-11-23 20:46
浏览 64

如何允许Android应用程序与网站通信

Hello there and please excuse me for my English or the silly question.. Due to my not deep technical background I might not use the right terms..

So..

I have created a web site (in PHP) where the users need to authenticate themselves in order to read some articles. The users are also able to post their articles or comment to the other articles.

What I need to do now is to transfer this simple functionality to an android app so the users can do the same thing through their mobile phones.

How should I approach this? How should I make the app to communicate with the website?

I am aware that directly access to the database is not a good idea at all.. So what are the alternatives?

So far I was thinking to have a url in the website where the user will POST data and actions of what he/she needs to do..

For example: In order to get the articles from a special category, they will need to send some POST data in the url http://www.example.com/mobile.php containing: - username - password - action(read) - options[category,since yesterday, order by rating]

And so goes on..

Then the web site will return the result in a JSON format which the mobile app will read and display it to the user's mobile.

A similar thing will happen when the user needs to write some articles or post comments..

Is the above-mentioned a logical approach or it makes no sense at all? Would you suggest something more professional?

Is there any link you could share please?

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • douzi3756 2014-11-23 23:50
    关注

    You can use web view to display web pages in android activity. Web View Android

    And to post data to web view you can use below code

    import org.apache.http.util.EncodingUtils;
    public class Example extends Activity {
      /** Called when the activity is first created. */
      @
      Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        WebView webview = new WebView(this);
        setContentView(webview);
        String url = "http://www.example.com";
        String postData = username = my_username & password = my_password ";
    webview.postUrl(url", EncodingUtils.getBytes(postData, "BASE64"));
    }

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog