How can I implement the search for a location? - android

I am planning on making a widget for android. It will basically show pollution data that is gotten from a government data rest endpoint.
My problem is that I want the user to search for and select the location they want data for, much like the weather widget.
I'm thinking that having a persistence database is overkill because the data probably won't ever change and I don't think the location list very big.
Should I put a textfile in the app that is being searched through or is there another more efficient way to approach this problem?
Thanks in advance!

Related

How to Call Remote Method service?

I'm developing in app, in which user can add weather card to know city weather. I'm able to populate cities with Google Places Autocomplete API & also can able to retrieve weather of selected city.
But my problem is as weather data is not fixed, it changes over time. So how can I update weather data in background once user creates that weather card. I need to do updates in background, I think I've to use android service but don't know where to start.
Ok, I will only guide you here,Nobody will provide you full code neither i will recommend anybody to do so, It is for your own good. You need to practice and explore the android programming world. So, here is my guidelines for you.
FirebaseJobDispatcher will fix you problem here. Before moving towards the FirebaseJobDispatcher you need to create a service class. For Services in android you should check this out.
Lets Talk about your service class.
Lets say it is FetchWeatherData class FetchWeatherData will extend to IntentService and will implement some methods. Inside onCreate you will write logic for fetching data from the server. Once you get the data from server you will store into the Database. Before storing into database you should check if database have the any record in it? If it does then delete it and store the new records in it.
Lets Talk about your Activity. Lets say it is ShowWeatherActivity. You will check first if you have any record in your database if there is no record then you will use FetchWeatherData to download weather data. Then show it.
Answer to your question can be very lengthy but i tried to explain as much which can help you get the idea of sync flow. Ofcourse your problem won't solve by reading this answer only. You need to go through these concepts
Services (Runs on main Thread)
Intent-Services (Runs in background)
Sqlite (For storing data)
I have added the helpful links in answer. Follow them. I hope this will help you somewhat.

Reading bunch of data from a server

i have a short question and it would be awesome if someone could give me some directions. I have a listview and an editText field. When I start writing I want fill out the listview with data obtained from some database. Like imagine I have a bunch of addresses somewhere. When I enter "a" I get bunch of addresses that start on a. I know I could use TextWatcher and Filter, I just need to know how to implement the communication between my app and database.
Thanks.
If you are a beginner to making Android backends I would recommend you look into firebase as a backend. It is easy to get started and there is a lot of sample code, especially for listviews. It is less-easy to shoot yourself in the foot so to speak with a backend as a service like Firebase and it is rather popular now.
Best of luck.
I think you can use a cursor adapter to populate the listview. Now to filter the content based on the user input you could use searchview with listview.
Here is a good tutorial :
http://www.coderzheaven.com/2013/06/01/create-searchview-filter-mode-listview-android/

How can i insert location into mysql database in android

Hi im developing android app based on location. anyone know is it possible to record live location and insert into MySQL database, so whenever user search it should show the map where he or she went with real time. if anyone knows please give an example
Of course it's possible. You would need to listen for location changes through Android's LocationManager service.
One your app is registered as a listener to the service, you will be given periodical updates about the device's latitude and longitude position. These values are what you should persist in a database.
Obviously, your app would need to ask for a few permissions in order to enable GPS tracking. If you're interested in showing the points aswell, you also need to setup a GoogleMap and request an API key for it to work.
As an addition, Android do not natively support direct writing into a MySql database. Your best bet wpuld be to implement a REST API to act as a middle man between your app and the database (hosted online) and post a write request through said API.
Here's some useful links for you to get started:
Official docs for location strategy
Official docs for LocationManager API
p.s., If my answer sounds too broad to you, it is because the thing you asked demands a broad anwer. Do some research and try to recreate an already existing example. Next time you're posting a question, try to narrow down to the very specific thing you'd want to know.
first you need to get current location location.getlatitude() ,location.getlongitude() then save in variable these variable pass the volley library just simple is that volley network method to save value in mysql database.
if you want to change value in database when user change location you should pass declare the method in locationChanged lisner.
There is no direct way to write into a MySQL database. You need to do a interface e.g. with an REST API.
The simplest way that will fit your need is to write some PHP files that are able to perform writes and reads from the database and POST/GET your data.
I found a pretty good example here:
http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/

what kind of database solution suits my mobile apps

I am looking into options how to realize the following use case. A iOS/Android user is using my app which gets its table view data populated by a cloud database solution. The user must be able to send back information (e.g. name + date) which needs to be send back to the database and gets stored there in a/different table/s. Moreover, I would need the db-solution to run automated reports based on the information sent back by the users (e.g. in an excel file).
So far I only found ragic.com might suit my needs. But what other options are out there, which might not be as fancy looking but will get the job done. Thanks guys!
A WebService is considered best practice regarding these matters. Have a look at this guys tutorial:
http://android.programmerguru.com/android-webservice-example/

ContentProvider appropriate for very dynamic data?

I'm an Android newbie, learning the SDK by creating some basic apps. I'm currently working on an app that will display content from a news aggregator with news items and comments on each item. Each news item has an 'id', and many comments associated with it.
Each results page will have a 'before' and 'after' reference id to the news item at the beginning of the page and the end, respectively. So each 'query' will be something like '/?before=$ID' or '/?after=$ID'.
It seems like ContentProviders are the preferred way to store data on android. However, the content of the site changes so much that I question whether or not using a ContentProvider would be wise.
I appreciate any insight.
Well content providers are used by the e-mail app to hold e-mail, gmail to store and sync its mail messages, gtalk and contacts to keep track of the people you know and their chat status, etc.
I am not sure just how dynamic you are thinking, but those are all pretty dynamic.
One way to look at it -- a content provider is just an API to access structured data across processes. If that API serves your purpose, well that's a good sign. The other aspect to them is that usually they are implemented on top of a SQLite database, and that is the easiest way to implement them because there is a lot of framework support for that. So you will most likely be using a SQLite database for your content provider impl. Is a database dynamic enough for you?

Categories

Resources