Android/PHP/MySQL project assistance - keeping server & phone app synced - java

I'm working on a solo project, using the aforementioned technologies. The aim is to create an quiz game for Android. The questions are created by the "quiz master" online beforehand and submitted to a MySQL database. They are then retrieved by the Android application. I have set up the link between phone & server using PHP, with the data sent over in JSON format.
I want each question to have a pre-allocated time which the user has to answer it and once this has elapsed, the Android app to prevent the question from being answered. The time is chosen by the quiz master and submitted to the database along with the rest of the quiz information.
As not everyone might retrieve the quiz from the server onto their phone at the same time, there are problems with regards to making sure someone doesn't get longer to answer the question than the other. As far as possible, I want to keep everyone in sync. It'll be difficult to make sure everyone has exactly the same time, but I'd settle for just having people not being able to delay retrieving the quiz and then getting the full 30 seconds (or whatever). For it to be fair, the countdown needs to start once the quiz has been started by the quiz master.
I'm struggling to think of a way to overcome this problem. I have a very basic client-server system set up and I can't think of a way to have the server keep track of the "time left" and then send a number to the phone, indicating the amount of time left.
Sorry for the essay, hope someone out there has an idea! It would be very much appreciated!! :)
All the best,
J

Perhaps you could have each users device keep track of how fast they answered the question and then compare the response time after the answer is submitted. For example: The server sends the phone a question and tells it that there is a 30 second time limit. As soon as the user views the question, the timer starts on their phone. Then say it took them... 14.79 seconds to answer correctly. The phone would send the info back saying how long each user took then compare them to see who answered the question first and who all answered within the time limit. This technique may not keep the quiz game perfectly in sync across all connected devices, but it should keep the game fair.

Related

How would I go about counting the number of times an external app has been opened and for how long?

I'm a beginner to Android app development, and as a good personal project to get started I'm trying to re-create something akin to StayFree or Checky. I want my app to be able to both count how much time a user has spent in an app during a day and how many times the app has been opened during the day.
I was thinking I could store the data using SharedPreferences, and came across this page in the Android developers documentation that I think could be useful in solving my problem, but, at a high level, I still don't really know what the outline would look like.

Ideas for my app that runs in the background

I'm developing an app that runs in the background that essentially snaps a front facing photo every time the phone is successfully/unsuccessfully unlocked. This isn't an original idea, but I'm developing it as a final project for my college android programming course, with no intent to sell this app. I have a general idea how I am going to go about this via some research but I keep running across a problem.
I know that it is hard and bad practice to run an app continuously in the background, so the idea is you put the app to sleep and set an alarm. My problem is that if the would be phone-snooper were to get really lucky, they could access the phone in between the alarms, and the owner of the phone would never know. I talked with my professor, and he proposed a couple ideas, but we could not come up with a definite solution, so I'm asking opinions here. Any idea how to subvert this dilemma? Thanks a ton.
Your approach is probably not appropriate for the problem. You can't "time" unpredictable events (like someone attempting to unlock a phone). Or else it's not clear how you are setting the alarm.
You should change the approach to an event-based approach.
Either provide a service for a lock-screen app so that it can use your code to capture a pic by sending login attempt events to it. You write that and provide an SDK/API.
Or else create your own lock screen app with your feature:
https://stackoverflow.com/questions/10864300/create-a-lock-screen-of-my-own

Is there a way to generate tweets during application development?

I'm developing a web site that's going need to generate tweets. I have a twitter account, but don't want to post tweets to that account until the site is live, or a least, in beta. I tried creating a second account just for the purpose of posting during the development process, but twitter wants a mobile phone # that's different from the first account, so this approach wouldn't work unless I had a second phone.
Is there a standard way to make sure all the pieces are working together without posting test messages to the web site's main account during development?
EDIT:
To post tweets with the twitter API, you have to go to the app permissions page and switch to "Read and write." When you do this, it shows the error:
Error
You must add your mobile phone to your Twitter profile before granting your application write capabilities.
Please read https://support.twitter.com/articles/110250-adding-your-mobile-number-to-your-account-via-web for
more information
My mobile phone is already registered with the production account. To register it for the dev account, I'd have to de-register it for the main account. I'm trying to avoid that. I need to have both active so that both accounts can be used at the same time.
Unfortunately with Twitters mobile side phones to numbers are a one to one relationship. You will have to resort to getting a different phone number luckily there are some good options out there.
Get a Skype phone number. Its about 5$ per month but would probably be the easiest and cheapest solution.
If your like me and dont like lingering monthly bills attached to your credit card then you can go to almost any local gas station or store and buy a cheap phone and pay as you go plan. This will give you limited capabilities with this phone (no internet access unless you pay). But on the up side you would have a physical phone and number and no monthly bill to accidentally forget about for 3 years before you remember about it. I bought one a year or 2 ago after I dropped my phone in a river for a one time fee of about $40.
Have you tried just to use an irregular phonenumber? For example 00000000. Twitter might not accept it, but it's atleast worth a try.

Real time game development

I want to develop a real time game for Android with libgdx. I need to update some variables even dough the game is not running.
For example I want the money to be increased 10 credits per hour (real life hour) so that you can go out of the game and come back an hour later and get that money anyway.
How can I do that?
Thanks
For real time, no need to setup your own server. Just use one of the public time server. Download NtpMessage.java and SntpClient.java from ntp site. Then run SntpClient.java with a ntp port. e.g.
java SntpClient 0.pool.ntp.org
You can use the code of SntpClient class and tweak if you need to.
When user gets out of game (pause state), get the time from ntp and save it. Once the user launches your game, get the time again and compare.
How about these two possible solutions (easy vs. difficult)
The difficult one...
To have a full control, you need to implement the logic in a server and have your application connect to it to get the credits (expensive but excellent solution). Your app will not hold permanent data. Your app will only be used for display, interaction, send/receive data from server.
The easy one...To simply use your app along with phone time. This solution costs much less but your app will be vulnerable against phone time manipulations.

Pushing or Pulling notifications

We want to implement a back end server [Java EE] for mobile application that sends notification to mobile on some events, I'm asking about the best/simplest approach whether Pushing or Pulling notifications, here you are my ideas/questions
1- The requirement is to send instantly the notifications to the mobile as long as the application is running no need to send if it's not running
2- I read that to push notifications to IOS or Android, I will need to connect to apple/google notifications servers, I felt that this is complicated especially that it requires low level socket programming, but based on number 1 and the project has limited time and budget, do we really need pushing ? and is it really complex
3- I read that pulling date may drain battery and consume data, but what if implementing a simple job on the mobile that runs only 3 or 4 times a day, invoking a simple web service on back end server asking for the notifications
P.S will be much appreciated if you can provide some tutorials for similar cases :)
1) If you're application is already running, is it connecting to the same location anyways? If so you might as well pull for the notifications at that point. However, if the app isn't actively connecting, i would attempt to avoid pulling.
2) Interacting with Notification servers on google and apple site directly, can indeed be a cumbersome task. However there are companies that have made this much easier for you. The advantage of using companies like urbanairship, xtify and mblox will get you started with sending push messages in minutes. (for an example take a look at http://developer.mblox.com/docs/ in the tutorial section).
3) depending on the data you try to present, end users now a days are used to instant data. I can't imagine a service whereby pulling 3 to 4 times a day is sufficient, however if your use case is truly limited to 4 times a day, and there is no other activity going on in the background process you create for this, you might as well have the background process running. But do think this through carefully... If at any point in time you want to increase the number of times a day you read, you might soon get to the point where a rewrite is needed to ensure end user satisfaction.

Categories