How do I allow end-user to add data to JSON file - android

I'm a novice when it comes to programming so bear with me. Currently I have a recycler view which pulls data from a JSON file in my assets folder and displays it. On the same screen where it is displayed I have created an 'add' button. This takes the user to another screen with a bunch of edit text fields where they can enter their own data, however, it currently does nothing. From my understanding, JSON files are read-only and so in order to add an element to the JSON array it needs to be saved to either internal or external storage (which I have no clue how to do). I have basically just followed this tutorial (https://www.youtube.com/watch?v=zdfbHzBmzk8&t=1859s) and now want to add a button where the user can input data and it gets added to the JSON.
Context:
The application is supposedly for a car dealership. I need to be able to create a list which displays the current stock of vehicles the dealership has. This is the data in the JSON file. The user should be able to add vehicles to the list, delete vehicles from the list or mark the vehicle as sold which should move it to a different activity and delete it from the current stock list. I will also need to be able to sort the list 3 different ways using a bubble, insertion and selection sort and I have a feeling this would be easier with my data stored in the JSON file.
TL/DR: How can I allow the user to add elements to a JSON file/array?

You can't perform the add/remove function on the JSON file which is in the app's asset folder. You can simply achieve this functionality in two ways:
Either you create a file that is stored locally on the mobile device and every time you need to add or remove some data from that file, you will need to read and then update that file.
Or you can create a local DB in your app, where you can store, add or update data based on your requirement.
From the above 2 ways, the second one (with DB) is more efficient than the first one. Also, you will find many resources that can help you in implementing that functionality.

Related

Reading and storing a set of data from Firebase Database?

I have set of data stored in Firebase Realtime Database (snapshot attached).
Click to View
I want to read this data when I press a button in my Android app and store it according to the person name, for example storing that Jack is 20 years old and Marry is an engineer, but I need to do this for more than just 3 users.
I'm able to call the data and read it but storing it in the way I described above is not working.
EDIT:
I added part of the code I'm working with, my main goal is when I click a button to call the data from Database, I'm able to do this but I can't figure out the best way to store this data in a way that I can use it. For example I want to display the name of the user and his role and age but I want to do this for as many users as available in database.
Code here

Best way to store references to .mp3 files with additional info, kept in mobile phone storage/external card

I'm currently working on audiobook player application I and I'm thinking about how to keep references to audiobook files.
So far I let user specify folder where books are kept and recognize subfolders / particular books.
Now I need to store those references. Audiobooks are always released in many parts, so lets say we have a 'Season of Storms' book and we have like 20 parts of that book: seasonofstorms-part1, seasonofstorms-part2 and so on.
I need to keep them linked to particular book and I need some more additional information stored, like what is name of the part that user finished listening to, and what is the time this part should start while opening book again.
So I though it could fit nicely in some JSON schema. I could make POJOs like:
Show with fields: name and List parts,
Part with fields: status [finished, notStarted, inProgress], time.
After resuming listening to a book application would search for part with 'inProgress' status and start playing at 'time'. I could parse these POJOs to JSON and keep them in SharedPreferences. What do you thing of this approach? Some better options? How could I make this work in any other way and what is the best approach in your opinion?

Android ListView Sourced from REST JSON response

I can't seem to find exactly what I'm looking for after a few day's worth of hunting, so if anyone has seen exactly what I'm trying to do elsewhere, I'd love a link or two.
Anyway, I'm trying to build an app to connect into an ERP system that returns user access information in JSON format via REST request using an e-mail address and password. Most users of the system only have a singular access role, so no big deal for them, but others have multiple roles. The trouble I'm having is taking these multiple access roles and adding them into a ListView where they can select the role with which they wish to use to gain access.
Trouble is, I need a display that uses two lines per selection (to properly display all user-pertinent data) and some way to record the user selection. The data useful in the background for the selection would not be displayed, as it would not mean anything to the user. I've been able to take the JSON response and map it to a custom class I designed for it without any problems (not actually all that useful, mostly only helps for discerning the results count prior to displaying multiple results to the ListView). But I can't figure out how to properly build the ListView layout and map the data to the layout. I'm having trouble understanding how to build the view and insert data into new list items.
The best I figure, if I can get the results to display in a ListView and then record the selection in the shared preferences, I'll be golden.
If the listview items being populated from some JSONArray then you could use listview.setOnItemClickListener to get the position of the selected item and match it from the array.Your question seems a little vague. Can you post some code of what you've tried so that it becomes a little clearer?

Android - associate a user to some list item

i'm developing an android application which allows different users to login and see a list of favourite songs.
Each user has its list of songs, and a song is an instance of the corresponding class Song, with some attributes (singer, year, title...). The MainActivity contains the form for the login, so the user has to set its Name and Password. After login, a second activity is started, and it contains the ListView with the user's favourite songs.
How can i associate a single user to its corresponding song's list?
I thinked to use a database to store the songs, but then?
Look at Parse it's very easy to use and let you focus on your android App, instead of spending much time writing and configuring a server-side application.
You need also to implement on your android application a service to handle json ( or xml, it's your choice ). This is an awesome library to handle json JSONP.
Look also to this link for an overview on RESTfulservices.
For example (getting user info):
You need an info on userA.
You format a json with the right info.
Start an http request to your server. It will answer you with another json containing some info.
Parse this json recieved and use the data in your app.
I hope I made myself clear.

Fusion tables permissions: how to restrict so that android app can only add new entries?

I'm writing an (Android) app (probably a website too) that logs some data from the user when they click a button. I'm currently playing with storing this data in a Google Fusion Table. How can I configure the permissions so that the app (or the website) is allowed to add an new entry to the table, and view it, but not change existing data?
I imagine I could do this by running a service in the middle that takes the data from the phone, and is auth'ed to write to the table, but would rather a simpler solution.
I think what you want is not possible, as there is no "INSERT only" permission, if you are the editor of a table you actually can edit and insert data.
see also issue 538
Maybe you can do something similar when using views, so a user can update this view, but not all the other data. Maybe you can hide the data from the editable view right after a user inserted it. Of course, this must be considered as a hack or workaround.
to get the idea: Flu Vaccine Finder example

Categories

Resources