繁体   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