[英]Implementing external Java class in Android Studio development
I'm working on a very simple android application that will let me search for a link from a given database.我正在开发一个非常简单的 android 应用程序,它可以让我从给定数据库中搜索链接。 I managed to create the application without any trouble using Android Studio.
我设法使用 Android Studio 毫无问题地创建了应用程序。 I have a button that is designed to open a search bar and search for the item in the database (searches for Key)
我有一个按钮,旨在打开搜索栏并搜索数据库中的项目(搜索键)
I created a basic web scraping program (using Java) to gather my data and place it in a dictionary in an IntelliJ project.我创建了一个基本的 web 抓取程序(使用 Java)来收集我的数据并将其放在 IntelliJ 项目的字典中。
My question is: How do I connect accessing the database (Java/IntelliJ dictionary) to the button in my android app(Android-Studio)?我的问题是:如何将访问数据库(Java/IntelliJ 字典)连接到我的 android 应用程序(Android-Studio)中的按钮?
The IntelliJ dictionary has 2 functions, one to get the data, and one to search for it. IntelliJ 字典有两个功能,一个是获取数据,一个是搜索它。 My Android studio code has one button as follows:
我的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
}
});
You can't access any directory on the computer from a mobile application.您无法从移动应用程序访问计算机上的任何目录。 Why you even store the data into a dictionary of the IDE, is there any purpose to it??
为什么你甚至将数据存储到 IDE 的字典中,有什么目的吗? That's alike shooting your own feet, but dearly.
这就像射击自己的脚,但代价高昂。 Instead just save to SQL, JSON or XML in the
res/raw
directory and then install to Android SQLite from there. 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. 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.
Maybe you need to write a server, and expose a Rest API for search.也许您需要编写一个服务器,并公开一个 Rest API 进行搜索。 And invoke this API from your Android application.
并从您的 Android 应用程序中调用此 API。
Some references:一些参考资料:
https://www.journaldev.com/9170/restful-web-services-tutorial-java https://www.journaldev.com/9170/restful-web-services-tutorial-java
https://restfulapi.net/create-rest-apis-with-jax-rs-2-0/ 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/ 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.