簡體   English   中英

在Android Studio開發中實現外部Java class

[英]Implementing external Java class in Android Studio development

我正在開發一個非常簡單的 android 應用程序,它可以讓我從給定數據庫中搜索鏈接。 我設法使用 Android Studio 毫無問題地創建了應用程序。 我有一個按鈕,旨在打開搜索欄並搜索數據庫中的項目(搜索鍵)

我創建了一個基本的 web 抓取程序(使用 Java)來收集我的數據並將其放在 IntelliJ 項目的字典中。

我的問題是:如何將訪問數據庫(Java/IntelliJ 字典)連接到我的 android 應用程序(Android-Studio)中的按鈕?

IntelliJ 字典有兩個功能,一個是獲取數據,一個是搜索它。 我的Android studio代碼有一個按鈕如下:


final Button ManualSearch = (Button) findViewById(R.id.DropDown);
        Scanner.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick (View v){
                // Access Database
                // call search method ()
                // search method will return data from database



            }
        });

您無法從移動應用程序訪問計算機上的任何目錄。 為什么你甚至將數據存儲到 IDE 的字典中,有什么目的嗎? 這就像射擊自己的腳,但代價高昂。 Instead just save to SQL, JSON or XML in the res/raw directory and then install to Android SQLite from there. Once I've even wrote a PHP script, which converts MySQL database to Android resource XML files... directly importing to SQLite on a computer would also be an option, then one can simply copy that database.

也許您需要編寫一個服務器,並公開一個 Rest API 進行搜索。 並從您的 Android 應用程序中調用此 API。

一些參考資料:

https://www.journaldev.com/9170/restful-web-services-tutorial-java

https://restfulapi.net/create-rest-apis-with-jax-rs-2-0/

http://www.androidhive.info/2014/01/how-to-create-rest-api-for-android-app-using-php-slim-and-mysql-day-12-2/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM