1

So far I think it's a security thing that you're not allowed reading/writing to an Android SQLite database outside of the containing app's process.

But are there advanced techniques or tools that can be used to achieve this?

For instance, I want to make a web interface with a textbox where the Android app would connect to and then I can run SQL queries via said interface to read the database or to insert records into it.

I'm writing this question because I'm really stumped. Usually my search gives opposite results which is accessing a remote database with an Android app.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
leondzn
  • 97
  • 9
  • You need to implement a backend, which will run your SL queries, and you will do requests to that ackend. This is how 95% of online apps do – Vladyslav Matviienko Nov 06 '17 at 11:07
  • have look https://stackoverflow.com/questions/19217835/can-an-android-app-connect-directly-to-an-online-mysql-database – Hemant Parmar Nov 06 '17 at 11:10
  • @HemantParmar that's exactly the opposite of my case. I intend to do it the other way around which is a web front-end that accesses my app's sqlite database. – leondzn Nov 06 '17 at 11:13

2 Answers2

1

You will have to develop an API backend. The mobile app ( client ) will communicate with the API and do the desired operation based on the response.

It's not possible to directly connect to the app sqlite database. You can send web request and get the info you want, handle it in your app to store it in the sqlite database

You will have to add security measures, so everyone can't access your API.

mrid
  • 5,782
  • 5
  • 28
  • 71
  • I plan on doing a web backend anyway. However is it possible at all to access the sqlite database directly? If so, which direction should I start looking (i.e. what techniques or tools should I be studying?) – leondzn Nov 06 '17 at 11:11
  • Hmm... I thought of something, maybe I could make a class in my app that receives CRUD statements in text form and then pass it as a parameter so the app runs those queries. I will have to handle the result set (i.e. the Cursor) one way or another, though. In JSON format perhaps? In any case, thanks. I think you helped shed some light in this one. You see, I know you really shouldn't have to access the SQLite db directly but this is a very specific case. – leondzn Nov 06 '17 at 11:21
  • it can work, but don't send sql queries from api to app. just send the data, and write the queries in the app itself. – mrid Nov 06 '17 at 11:29
  • As much as I'd love to do that instead, I was specifically instructed to make something that passes SQL queries directly. :p – leondzn Nov 06 '17 at 11:32
  • :D if its required, then you can do that. But it will be a security loophole – mrid Nov 06 '17 at 11:36
0

So far I think it's a security thing that you're not allowed reading/writing to an Android SQLite database.

Apps can read and write to their SQLite databases. Otherwise, the database would not exist.

I want to make a web interface with a textbox where the Android app would connect to and then I can run SQL queries via said interface to read the database or to insert records into it.

You are certainly welcome to embed a Web server into your app. For example, Stetho does this to integrate with Chrome Dev Tools, offering your SQL interface among other things.

However:

  • Doing this for anything other than a debug build of your app is very risky, as securing a Web server is difficult enough when it is on a traditional server environment, let alone an Android device

  • The Web server is only accessible by whatever can reach the device via an IP address, which means it's usually only useful on WiFi (where it could be reached by other devices on the same WiFi LAN segment)

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491