I'm making an App based on money, and one feature (not of the main ones) needs to convert your amount of money in any currency (or at least into the most important ones) you need.
So if I had 50 Euros, and I select Pounds in the Spinner, the value should change from Euros to Pounds, etc.
Is there a code or a shortcut to implement this operation?
Otherwise, how may I code a method to do just this?
This is not exactly trivial to implement. Currency values fluctuate frequently enough that to be reasonably accurate you will not be able to just hard code values. You will need to send a request to some kind of currency tracking service's API, like this one at appspot. This will typically result in some kind of JSON package that you will have to parse.
When to do this exchange depends on your application. If you are doing something where up to the minute accuracy is very important, like a trading app, you would have to make the call when the user requests the information. Otherwise you could call something like openexchangerates.org that returns a single json with a very large set of currency values when the user opens your app, and cache those values until needed. That way you can more gracefully handle things like not being connected to the network, but the downside is you will not necessarily be as accurate.
Related
I am searching for a method to get notified on my android phone, if the first occurrence of a element of a certain class has a value larger than x on a multiple times a minute updated website.
Though this website is not subject to constant updates, here is an example using amazons "100 Books to Read in a Lifetime":
Currently the first book on the site is sold for $5.99. I would like to be notified on my phone, if it is offered for 5.50 or less. Therefore I would need to implement a method to retrieve the price inside the first occurrence of <span class="a-size-base a-color-price acs_product-price__buying">($5.99</span>), check if the number substring is smaller or equal to 5.5 and notify me on my phone.
Keep in mind, amazon is just an example, I am in search for a general and customizable solution on an often changing website.
What would be a good way of implementing such a notification system?
P.S.: This is my first post on stackoverflow. If you think I should add something or rephrase my question, please let me know!
You can use JSOUP for parsing the html code and then using the selector to get the value of the item, And for the changes in price you have to schedule a job which will run in background and check for updates in a given interval of time, Save the price in device locally on every request and while doing the next request compare the value and if there is any change in value show notification.
In my app, I'd like to keep track of time away from the app, so that if the user is away for say, 2 hours, and come back, they receive 1 in game currency.
In practice I could easily do this by using a date object to get the current time in onStop, saving that date object, and comparing it to a new date object when they return.
However, I have a feeling this can easily be spoofed by change the internal date settings.
Is there a more secure way? Should I just put a cap on how many hours away you can bank up? I'd love some insight. Thanks as always.
you can try to make more secure code in the app, but the safest way is to request something from a server
if you are app is already using internet permissions consider making an HTTP request to get time.
look at this site for example
http://www.timeapi.org/
if you have backend to support your app that would be extra better
if you are not using internet permissions it might not be worth it to add it just for this, you might consider a different "offline" solution
I need to get the cost of call after the call is ended, ie, the Cost per call as subscribed with the Service Provider. Is there anyway to get this information on the device programmatically?
Thanks
This cannot be possible.
Cost per call is dependent on the Service Provider (Carrier).
Carrier charges depends on so many factors like the plan you have selected and the like. For postpaid cards, this is even more difficult because there might be applicable discounts etc.
May be, you can consider discussing directly with the service operators and ask for their APIs (IF any) and calculate the last call cost.
I dont think this is possible.Theres no way for your app to get the values unless you provide them.
I'm wondering which is the best way to store a time into a database.
Is it better to store the time in millis as a LONG value or use the sql DATE type.
I want to store a time into the SQLite database of the android device and send it later to a server. Which is the best way in consideration of performance.
I've encountered both methods and both are valid options. Personally I would go with the sql DATE method since you have many predefined methods with reading/manipulating/writing dates in SQLite, as explained here. Storing time in millis is fine if you're willing to run extra calculations to verify the accuracy of the data later on, coming from a QA perspective.
Depends entirely what you are going to do with the time. If you are just going to display it, a text field is perfectly fine. If you are going to convert it do different formats, a long is probably the way to go.
As everyone else is saying, it all depends on what you want to do with it.
Considering your situation, I would store it in whatever format the server you are going to send it to needs.
As the saying goes, there are many ways to skin this particular cat. For example: in some instances I've taken the date and converted it to an int in the format of yyyymmdd, that way I can do simple less than/greater than/equal to comparisons without having to resort to the different time functions in SQL.
Assume we have a lot of android devices that trying to submit real-time data(a time stamp and some numbers) to an django application.
What we need to do is get the mean value of those data that being submitted per second and constantly update an android device.
How can I achieve these goal?
Your best bet is to memcache the data then store it in the datastore. Your mention of "mean value of all these data per second" doesn't make much sense to me; unless you have a lot of users or are generating a battery-draining amount of data, the mean value per second will probably just be whatever data happened to be submitted that second. Also, "realtime" may have deceived you; it will take time for data to be transmitted to the server and back down to the phone. Especially on EDGE and slower data networks, it could cause a lag of a few seconds.
It may be practical to do per-minute mean calculations; to that end, I would simply do a memcache tuple of the number of values received that minute and the mean they represent. Then when you get a new value, recalculate the mean (multiply the mean by the number of values [not including the increment] and add the new value, then divide by the new number of values). Store this in memcache, and move on. It's unlikely your data will get evicted within that minute if you're using memcache wisely, and if it is evicted, you lost at most a minute of data. If that's unacceptable, back it up to the datastore.