Can two Android devices, running different applications, use the same SQLite Database?
I read this question and wondered if the same would apply to my situation.
I want to write accelerometer
values (x, y and z) from an Andro开发者_Python百科id
phone to a database
and retrieve it with another app on a tablet to display a graph of the values changing over time. This does not have to happen in real time.
So basically my questions are:
1) can two different applications on two different Android
devices use the same SQLite
database?
and
2) how do I specify an IP
so that the one app on the phone writes to a specified database and the other app on the tablet reads from that same specified database?
I can already read the Accelerometer
values and I know how to create a graph, but I'm having trouble with the database component of my project since everything I come across seems to be storing the values on the device's SD card
or in a database that is only accessible to the device itself and no other applications or devices.
I've read about specifying a static IP by first obtaining a ContentResolver
:
ContentResolver cr = getContentResolver();
then adapting the settings
:
Settings.System.putString(cr, Settings.System.WIFI_USE_STATIC_IP, "1");
Settings.System.putString(cr, Settings.System.WIFI_STATIC_IP, "6.6.6.6");
and then enabling the permissions
: WRITE_SETTINGS
and WRITE_SECURE_SETTINGS
.
but I'm not sure where exactly to write this or how to use it correctly.
Please direct me to where I can find some more information regarding setting up SQLite
databases and how it can be used by two different applications on two different Android
devices?
Thank you in advance.
P.S. I'll update this question with some of my code soon.
can two different applications on two different Android devices use the same SQLite database?
No more than two Web servers running on two different continents can use the same MySQL database. Only processes running on a device with filesystem access to a file can read and write to that file.
how do I specify an IP so that the one app on the phone writes to a specified database and the other app on the tablet reads from that same specified database?
You don't. Android is not a server platform.
At best, you might be able to pull this off if both devices are on the same WiFi LAN, and you write a Web service that exposes a database from one device. This, of course, exposes you to the same security issues that you would have with a Web server, without the benefit of firewalls and the like.
I want to write accelerometer values (x, y and z) from an Android phone to a database and retrieve it with another app on a tablet to display a graph of the values changing over time. This does not have to happen in real time.
Hence, you do not need two devices to access the same database. You need them to work with the same data.
So, you could have the phone send the data to some server via a Web service, and have the tablet retrieve the data from that server via the Web service.
Or, have the phone send data to the tablet via Bluetooth.
Or, if you feel the security is adequate, have the tablet expose a Web service via WiFi that the phone uses (though this really scares me, particularly if the tablet might join some other network, such as by being moved).
In neither case does the phone nor the tablet necessarily even have a database, let alone try to directly share it.
A SQlite database is private to the application which creates it. If you want to share data with other applications you can use a Content Provider.
Although not SQLite, I believe this can be achieved using PouchDB, where you would host one shared remote database which would then sync to two seperate databases for each application.
https://pouchdb.com/
精彩评论