1

I have a quiz app which populates a sqlite database with questions of around 20 different categories. I want to implement in app billing so that if someone purchases Category1 for example, then these questions are added to the database and no others. Some of my questions fall within two categories so let's say Category1 and Category2.

try {
            for (int n = 1; n < sqlString.length; n++) {

                db.execSQL("INSERT INTO " + DATABASE_TABLE + " VALUES ("
                        + sqlString[n] + ");");

            }
            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }

This is my current set up in the SQLite class onCreate method. sqlString is a string array containing all my 500 questions so far.

I'm going to store whether a category has been bought in another table (but I am open to other suggestions on how to do this). I plan on creating a class which reads this database setting up boolean values of true or false whether each category has been bought. So

boolean cat1 = CheckIfCategoryHasBeenBought(category1)

etc. Then if it has been bought I will implement a method such as

boolean[] catChecker = {cat1, cat2, cat3, etc....}
SQLite info = new SQLite(this);
info.open();
info.addQs(catChecker)
//this will pass the true and false boolean values for each method then 
//based on that I choose to implement or not
info.close();

However I don't know if this is even a good way to do it. I'm not sure how to check if the value has already been added (as a result of it crossing over with another category that's been bought). I was thinking a cursor would be best to check if the value is already added however how do I get the cursor to search?

The ways I've thought this could be achieved is

1) I create a string array only with the strings associated with bought questions. 2) I create an if statement within the for loop above which checks whether the string is from a bought category 3) I give the value "null" to all strings that haven't been bought then add an if statement only executing the SQL if the sqlString[n] is not null.

Do you guys have any idea how it would be best to set this up?

2 Answers 2

0

Have you thought about starting with a full database - i.e. containing all questions that could be purchased by anyone - and then delete those that are no longer applicable?

1
  • I didn't want to do this because it's much easier to hack. I decided I would wrap each question in an if statement with each and every category that applied to it and if the question hadn't been bought it remained set as null. Nov 7, 2012 at 19:09
0

There are lots of ways to do this, and I think there will be more than 1 good answer. If you have a server, you can do things like return a list of authorized databases/strings/etc. You can use that to reference different tables. You also can create a table or use sharedpreferences of which tables are downloaded. The list goes on.

The server option would add a layer of security. The stored table index would be easier to pirate, but also might be easier to implement and gives you the ability to use the categories offline.

1
  • I don't have the ability to use a server :/ I'll probably stick with the table or shared preferences and run a license check every week or so or something similar. Any ideas for the rest of the question? Nov 2, 2012 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.